Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!wuarchive!texbell!vector!attctc!richardh From: richardh@attctc.Dallas.TX.US (Richard Hargrove) Newsgroups: comp.lang.c Subject: Re: MEMORY ALLOCATION IN TURBO C Summary: memory allocation in turbo C with malloc(). Keywords: Turbo C malloc heap packet format Message-ID: <11086@attctc.Dallas.TX.US> Date: 21 Jan 90 16:21:10 GMT References: <1332@maestro.htsa.aha.nl> Organization: The Unix(R) Connection, Dallas, Texas Lines: 26 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 -------------------