From: Dibyendu Majumdar
the C compiler from V7/V10. I wanted to check if
anyone here knows
about the memory management in the compiler (c0 only for now). I am
trying to migrate the memory management to malloc/free but I am
struggling to understand exactly how memory is being managed.
Well, I don't know much about the V7 compiler; the V6 one, which I have looked
at, doesn't (except for the optimizer, C2) use allocated memory at all.
The V7 compiler seems to use sbrk() (the system call to manage the location of
the end of a process' data space), and manage the additional data space
'manually'; it does not seem to use a true generic heap. See gblock() in
c01.c:
https://minnie.tuhs.org//cgi-bin/utree.pl?file=V7/usr/src/cmd/c/c01.c
which seems to use two static variables (curbase and coremax) to manage
that additional memory:
p = curbase;
if ((curbase =+ n) >= coremax) {
if (sbrk(1024) == -1) {
error("Out of space");
exit(1);
}
coremax =+ 1024;
}
return(p);
My guess is that there's no 'free' at all; each C source file is processed
by a new invocation of C0, and the old 'heap' is thrown away when the
process exits when it gets to the EOF.
Noel