Re: [cc65] Detecting first free byte of RAM?

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2001-03-18 23:53:09


On Sun, Mar 18, 2001 at 07:25:45PM +0100, BlackJack/Civitas wrote:
> All except the official malloc() method (and maybe using _horg/_hend) may
> result in problems with the C-stack.

To be more exact: That is not a problem with my answer, but with the original
question:-)

Jim didn't ask how to determine the size of the free memory block, so I
assumed that he wasn't going to use a really large blocks of memory.

To add the needed information: The program code and data lives in low memory,
the C stack lives in high memory ($D000 for a standard C64 setup) and grows
downwards(!). The free space is located between both areas. If you're using
this free space, you have to be careful, since the size of the C stack is not
fixed, so you may overwrite it (or the growing C stack may overwrite your
data).

The 6502 does not have hardware memory protection, and cc65 does not generate
any code to check for stack overflows. This means that there is always a risk
that the stack grows into the heap. So even using malloc() and free() does not
protect you from getting stack problems. On the other side, the default stack
size is 2K which should suffice for even large programs.

A long time ago, I had plans to add an option to generate stack checking code
(the subroutine that does this has been part of the library for a long time,
it's just that it is not called by the generated code). As usual, I don't
remember, why I didn't finish it:-)

Regards


	Uz


--
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2001-12-14 22:05:39 CET