Newlib Hitachi SH-2 _sbrk() and malloc() problems?

Mon Jun 4 12:39:00 GMT 2007

Israel Jacques wrote:
> The problem mainly is that _write() crashes the system. I do not have
> a patch for this since I would first like to understand why _sbrk() is
> set up this way.

Because it is. :)

It's fairly normal for the program code to live at the bottom of memory. 
The heap then grows upwards from there, and the stack grows downwards 
from the top of memory.

Any other layout requires that you preallocate space to the heap and 
stack. This means that you can run out of stack space, but still have 
loads of unused memory allocated to the heap, or vice-versa.

But with this layout, when the heap and stack meet in the middle then 
you really have run out of memory - every byte of available memory has 
been used.

In short, it's the most efficient way (assuming no virtual memory).

If you don't want it that way, then it's simple enough to reimplement sbrk.


More information about the Newlib mailing list