[comp.lang.c] MEMORY ALLOCATION IN TURBO C

joaquinv@solist.htsa.aha.nl (Joaquinv Villar) (01/19/90)

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.

Thanks.




-------------------------------------------------------------------------------
Joaquin Villar C/Assembly programmer.
joaquinv@solist.htsa.aha.nl
-------------------------------------------------------------------------------

richardh@attctc.Dallas.TX.US (Richard Hargrove) (01/22/90)

In article <1332@maestro.htsa.aha.nl>, joaquinv@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
-------------------