i implemented my own versions of the b2Alloc and b2Free functions that do not pad the front of the allocation with 4 extra bytes to keep track of the total number of bytes allocated and i began hitting asserts in b2BlockAllocator::Free. the assert that checks that the memory you're freeing is not within a chunk with a different block size fails. specifically:
is false when it shouldn't be because of the addition of "gap." gap is calculated as the offset within a b2Chunk structure of the blocks pointer which is 4. my question is: how is that gap, as calculated, related to the size of the prefix on the allocated block of memory in any way? is it just a coincidence that they both happen to be 4 and so this assert doesn't normally fail? it seems like the way gap is calculated is unrelated to the value it's supposed to represent - am i missing something?
thanks for your help!
Code:
(int8*)chunk->blocks + b2_chunkSize + gap <= (int8*)p
is false when it shouldn't be because of the addition of "gap." gap is calculated as the offset within a b2Chunk structure of the blocks pointer which is 4. my question is: how is that gap, as calculated, related to the size of the prefix on the allocated block of memory in any way? is it just a coincidence that they both happen to be 4 and so this assert doesn't normally fail? it seems like the way gap is calculated is unrelated to the value it's supposed to represent - am i missing something?
thanks for your help!