Mail Archives: djgpp/1998/06/24/06:32:14
>How does free() know how much memory to return to the heap? Does it have
>to be the originally malloc()ed pointer or can it be a different pointer
>to the memory that was allocated? I'm writing a linked list and keeping
>pointers to each element around kinda defeats the purpose... thanks in
>advance for any help
>
One possible heap implementation approach could be the following:
heap manager holds a list based structure of allocated blocks and malloc
returns a pointer to a data record of a heap block description structure
which includes block size record calculated as a fixed negative offset from
the mentioned data record starting address. Look at any heap manager
sources. IMHO, heap manager sources in DJGPP RTL are too optimized
for speed and not for readability. I suggest to choose a bad (but simple)
heap manager, e.g. from Borland C++ RTL :-).
----------------------------------------------------------------------
Aleksey Kondratyev
Ph.D. student of Ulyanovsk state University, Russia
http://www.mv.ru/~akondra
E-mail akondra AT mmf DOT univ DOT simbirsk DOT su
akondra AT mv DOT ru
If the address above contains no-spam-, please,
remove it when replying.
- Raw text -