This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.

Andrew




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]