HeapBlock with size


#1

Is there any reason why the heapblock doesn’t have a size member ?
From what I understand, in order to use both realloc, and/or allocate, you need a size variable in your class in addition to the heap block, so you have to store the allocated size in the same level as the heap block.
To me, it’s a bit opposite to OOP.
What about adding a “const int size() const throw()” method for fetching this ?

Also, it would be faster because you can avoid (slow) free’ing the block in case the new size match the previous one (or is less than the previous one depending on if you allow changing semantic).

Maybe I’m preaching for the actual MemoryBlock ?


#2

Yeah, I think you’re just asking for MemoryBlock there!

HeapBlock is basically just a safe, c++ version of a pointer that was obtained by malloc/realloc. It’s used in many places where the size is constant or unimportant, so adding a size to the class would bloat a lot of code unnecessarily.