Turboc 2.0 malloc/free/coreleft

Erik Naggum enag at ifi.uio.no
Fri Feb 1 10:23:08 AEST 1991


In article <1991Jan30.172158.2769 at ux1.cso.uiuc.edu> bloomqui at osiris.cso.uiuc.edu (Kim Bloomquist) writes:

   The program performs as expected.  Memory is allocated to hold s then
   free() deallocates s making available the same number of bytes (63,704)
   we started with.  However, when the comments are removed from around the
   printf/gets statements the following output is produced.  The last call
   to coreleft shows only 63,082 bytes free and not the original 63,690 bytes.
   Question 1:  What is being allocated to the missing 608 bytes?
   Question 2:  Can this memory (the 608 bytes) be deallocated?

printf and gets are stdio routines, which allocate buffer space for
hitherto unused streams.  See setbuf(3) for a way to disable that.

BTW, since this buffer space allocation occurs after your allocation,
the free may not actually release any memory because your allocated
block is no longer the "top-most" allocated block.  Your "608 bytes"
may thus be inaccurate.

--
[Erik Naggum]	Snail: Naggum Software / BOX 1570 VIKA / 0118 OSLO / NORWAY
		Mail: <erik at naggum.uu.no>, <enag at ifi.uio.no>
My opinions.	Wail: +47-2-836-863	Another int'l standards dude.



More information about the Comp.lang.c mailing list