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

Jan Dubiec jdx at slackware.pl
Thu Nov 27 03:28:21 CET 2003


Hello,

I am porting Nut/OS to Renesas' H8/3068F MCU. Unfortunately, I am not
sure if I understand NutHeapAlloc()/NutHeapFree() source properly. Let
assume that a thread wants to allocate N bytes from the heap. IMO in
such case reserved memory area looks as follows:

+------+------------------------------------------------+----------+
|header|       available for a thread                   |0xDEADBEEF|
+------+------------------------------------------------+----------+
 sizeof(HEAPNODE)           N bytes                        4 bytes
    bytes
       ^
       +-- pointer returned to a thread (application)
Am I right?

Next, there is following code at the beginnig of NutHeapAlloc():
    /*
     * We need additional space in front of the allocated memory
     * block to store its size. If this is still less than the
     * space required by a free node, increase it.
     */
    if ((size += 6) < sizeof(HEAPNODE))
        size = sizeof(HEAPNODE);

What does 6 mean? Is this sizeof(HEAPNODE)/2 + sizeof(0xDEADBEEF)?

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