I am working on a program for my OS class and it invloves calling
sbrk(0) after malloc(). According to the "The design and implementation
of 4.3BSD UNIX Operating System," malloc calls sbrk for to allocate
memory. However in Sun's man page of sbrk it says
Programs combining the brk() and sbrk() system calls and
malloc() will not work. Many library routines use malloc()
internally, so use brk() and sbrk() only when you know that
malloc() definitely will not be used by any library routine.
But in the man page of malloc:
... When there is no suitable space already free, the
allocation routines call sbrk() (see brk(2)) to get more memory
from the system...
As some experiments:
The return values of the function are different while compiling
with gcc and Sun cc (on a Sparc 10 with 256 MB of RAM).
So, first of my questions is that which of the man page is correct? Can I use
sbrk with malloc? Second, why cc and gcc give different answers? Third, where
can I find more information about Sun's implementation of these system calls
and library functions?
Thanks in advance.
Ta-Wei "David" Li
UNIX Consultant, University of Southern California
Member, League for Programming Freedom
"Innovate, don't litigate."