Mail Archives: djgpp/1997/11/08/15:34:24
At 04:32 11/7/1997 +0100, Christopher Croughton wrote:
>Nate Eldredge wrote:
>>
>> IIRC, sbrk() is POSIX and has been in Unix forever.
>
>It doesn't say POSIX in the man page here (Dec Alpha, OSF/1), but that
>doesn't necessarily mean anything...
No, you're right, that was a mistake. It isn't POSIX (I checked the Linux
man page), but it's a *very* standard Unix feature.
>> AFAIK, yes. It gives your program N more bytes of memory, and returns a
>> pointer to it.
>
>And frees it? ISTR a comment here about it not actually freeing the memory
>again.
That's correct. You usually can't free it. Since your address space is flat,
you could only deallocate the last thing you allocated:
char *p;
p = sbrk(1000);
/* do stuff with p */
sbrk(-1000);
But I think many platforms don't support negative arguments to sbrk()
anyway. Once you get memory, you have to keep it until your process
terminates. That's why free() doesn't return memory to the system, and just
deals with it itself.
Nate Eldredge
eldredge AT ap DOT net
- Raw text -