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

Jan Dubiec jdx at slackware.pl
Thu Nov 27 11:48:19 CET 2003


On Thu, 27 Nov 2003 15:38:44 +1300, "Ralph Mason" <ralph.mason at telogis.com> wrote:
> You are correct (from my understanding), however it's not portable like that
> b/c it assumes sizeof (void*) == 2 which it doesn't always
> 
> 
>     /*
>      * 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.
>      *
>      * And space behind it for the End of mem marker
>      */
>     if ((size += (sizeof(u_int) + sizeof(u_long)) ) < sizeof(HEAPNODE))
>         size = sizeof(HEAPNODE);
Well, but I still don't understand why there is sizeof(u_int). IMO
there should be sizeof(HEAPNODE) instead of it, although I think that
the whole if() is useless because condition always evaluates to false,
even if size is 0. IMO there should be one simple expresion:
    size += sizeof(HEAPNODE) + sizeof(u_long);
                    ^                ^
allocate space -----+                +----- allocate space for
  for header                                    end maker

[.....]
> I have ported all the heap stuff so that is *should* work with any sized
> pointers if you want it.
I would be greateful if you could send it to me. I would like to
compare your changes to mine.

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