Date: Sat, 8 Nov 1997 12:33:11 -0800 (PST) Message-Id: <199711082033.MAA01420@adit.ap.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: Christopher Croughton From: Nate Eldredge Subject: Re: Memory allocation Cc: crough45 AT amc DOT de, djgpp AT delorie DOT com Precedence: bulk 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