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

Mike Cornelius mikec at call-direct.com.au
Thu Nov 27 05:15:42 CET 2003


Hi Jan,

Why 're-invent the wheel' there are already 2 H8 ports I did one, and at
about the same time another fella called Tyou did one too.
Surely it would be easier to use one of ours ?

Mine is written to work on particular hardware (Nokia Smart Adapter), I
think Tyou's may be more generic.

To answer your question 6 is the sizeof(0xDEADBEEF) + the
sizeof(HEAPNODE:hn_size)  
So on the H8 it shoud instead be 8 since it's a 32bit machine.

Let me know if you want my port and I'll tell you how to get it.

Mike

-----Original Message-----
From: en-nut-discussion-bounces at egnite.de
[mailto:en-nut-discussion-bounces at egnite.de] On Behalf Of Jan Dubiec
Sent: Thursday, November 27, 2003 1:28 PM
To: en-nut-discussion at egnite.de
Subject: [En-Nut-Discussion] Understanding NutHeapAlloc()/NutHeapFree()


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.
_______________________________________________
En-Nut-Discussion mailing list
En-Nut-Discussion at egnite.de
http://www.egnite.de/mailman/listinfo.cgi/en-nut-discussion




More information about the En-Nut-Discussion mailing list