[TUHS] Memory management in Dennis Ritchie's C Compiler

Paul Winalski paul.winalski at gmail.com
Tue Aug 18 06:34:17 AEST 2020

On 8/17/20, Dibyendu Majumdar <mobile at majumdar.org.uk> wrote:
> Yes, it only uses sbrk(). One consequence I think is that sbrk()
> expands the process memory without invalidating existing use of memory
> - so the code is able to periodically expand heap while retaining all
> existing allocations.

If everyone does that, you can call other people's code without fear
of stepping on their memory when you allocate memory in your code.
Using a negative value to decrease the break is more problematic.
malloc() usually uses sbrk() to extend its heap.

When we ported DEC's GEM compilation system to Unix, I used sbrk() to
extend memory and built my own multiple heap allocation scheme on top
of that.  I could have used malloc() to allocate the heap chunks, but
there was no point.  Might as well cut out the middleman.

-Paul W.

More information about the TUHS mailing list