i have looked at it a little. I didn't fully understand some it's
parts ("hook"s), but it works similary like my heap manager.
The hook mechanism allows other software to catch calls to and
exits from the various exported routines. See the malldbg module.
Also the documentation in nmalloc.txh. IIRC readme.txt explains
how to convert it into html with standard software.
Differences i spotted are:
- my heap manager saves original requested size of block, and
returns it when asked about size of block by caller. Aligning
aspect is thus hidden from caller.
Pointless, because the original allocator knows how much he
requested. No need to save it.
- there is block signature in header, which helps greatly to catch
bad pointer to block or heap corruption.
With the 'SAVEMEMORY' or something defeated, there are signatures
in nmalloc blocks. They involve expanding the overhead per
allocation from 16 to 24 bytes.
- it doesn't have speed-ups like yours freehdrs[] array... maybe
i will steal this idea in future
also, you can easily catch out-of-heap pointers instead of causing
crash... just ensure they are in range <heapptr, heapptr+heapsize)
before accessing them.
Where a crash is forced, it is known that the memory arena has been
fouled, and there is no way to recover. Otherwise the user can
control the actions of signal and raise. There is no such thing as
a range and heapsize, since there may well be multiple 'heaps' in
use. that is up to the actual action of sbrk. I think sbrkbgn is
the thing that keeps track of multiple heaps. All this, except the
use of sbrk, is fully standard C outside of the assumption of
arithmetic on the pointers.
the test themselves spare me from some more thinking, i will rewrite
some of them for my lib, thanks again.
PS: use "bsr" instruction for faster "size2bucket()" function on x86
No such routine in standard C. It is up to the compiler to decide
what instructions to use.
I just uploaded a revision last night, so you may want to reload
your copy.