MEMORY ALLOCATION IN TURBO C

Richard Hargrove richardh at attctc.Dallas.TX.US
Mon Jan 22 03:21:10 AEST 1990


In article <1332 at maestro.htsa.aha.nl>, joaquinv at solist.htsa.aha.nl (Joaquinv Villar) writes:
> When i allocate memory with the malloc() function and then make a   
> memory dump i see malloc() has allocated 8 bytes more then i
> requested. 
> These 8 bytes are used by the free() function to free the allocated memory.
> 
> Can anyone tell me the exact format end the exact meaning of those 8 bytes.
> I was compiling in the compact model with turbo C 2.0.
> 

As you surmised, the overhead storage is used by the dynamic memory 
allocation run-time support code for heap management. The information 
kept in the overhead storage associated with each heap packet is usually 
not made public, though it's usually not difficult to reverse engineer 
(packet size, is it allocated or free, where is the next packet, etc.)
In the case of Turbo C, if you have access to the run-time support source 
you can actually see how the overhead storage is defined.

Of course any code that depends on the information stored in the packet
overhead area is not even portable between different versions of the 
same compiler. There is no guarantee that other versions of the compiler 
will not use a different scheme.

Richard Hargrove
...!attctc!richardh
-------------------



More information about the Comp.lang.c mailing list