Re:A tiny Unix dynamic memory allocator library
by userbinator on Saturday September 23, 2017 @01:12AM
(#15318256)
It uses calloc() which then uses... the system library's malloc(). I'm not sure what utility this has --- all it does is add some headers and footers to the allocated block in an attempt to catch overflow writes, but practically all existing malloc()s do that already.
Re:A tiny Unix dynamic memory allocator library
by hawkinsw on Saturday September 23, 2017 @01:40AM
(#15318341)
I wondered the same thing! If the goal is to add "debuggability", then there are other options out there too -- dmalloc and electric fence, to name just two.
I went to the repo fully expecting to see a call to brk() somewhere in the code.
Re:A tiny Unix dynamic memory allocator library
by spc476 on Saturday September 23, 2017 @03:29AM
(#15318652)
The author of this could have picked a better value to fill in the guard area. For the x86 architecture, 0xCC is a good choice. It's an unusual negative value, a largish unsigned value, most likely an invalid address (if dereferenced as a pointer) and if executed, is the INT 3 breakpoint instruction. Other architectures would require different values, but at least pick one that has a good chance of blowing something up if used.
Re:A tiny Unix dynamic memory allocator library
by unwind on Saturday September 23, 2017 @03:16AM
(#15318611)
It disallows free(NULL) which the standard allows, so it's not a drop-in replacement. Hard to see the added value although allocators can be good for learning.
Re:A tiny Unix dynamic memory allocator library
by kabdib on Saturday September 23, 2017 @05:19AM
(#15318928)
Maybe as a debugging cover for memory (but then you'd expect functionality for heap checking, block tracking and leak detection, etc). Forbidding a null pointer on free is a breaking change and a little naive. It's not terribly useful.
I went to the repo fully expecting to see a call to brk() somewhere in the code.
Will