[En-Nut-Discussion] Understanding NutHeapAlloc()/NutHeapFree()

Jan Dubiec jdx at slackware.pl
Thu Nov 27 18:23:48 CET 2003


On Thu, 27 Nov 2003 12:37:00 +0100, "Oliver Schulz" <Oliver.Schulz at bong.de> wrote:
> Hi Jan,
> 
> > > To answer your question 6 is the sizeof(0xDEADBEEF) + the
> > > sizeof(HEAPNODE:hn_size) 
> > But why not sizeof(HEAPNODE)? I still can't understand this.
> 
> That's simple. The HEAPNODE structure is only fully used, if it marks a free
> block. In this case hn_size contains the size of the free block and hn_next
> points to the next free block.
> 
> Then if you use NetHeapAlloc() and a free block is allocated, the block is not
> any longer part of the free block list and therefore the hn_next member isn't
> used any more. So the RAM space needed for hn_next can now be used for the newly
> allocated ram. Thats the reason why hn_size is the first and hn_next the last
> member of HEAPNODE.
Thanks a lot Oliver. All is clear for me now. IMO your explanation should be
included somewhere on the top of heap.c as a "theory of operation". ;-)

Regards,
/J.D.
-- 
Jan Dubiec, jdx at slackware.pl, mobile: +48 602 101787

Głęboka wiara wymaga płytkiego rozumu i nikłej wiedzy.



More information about the En-Nut-Discussion mailing list