box2d
box2d copied to clipboard
Pass Original Allocation Size as Second Argument in b2FreeFcn
I am using box2d with custom allocators but would need the original allocation size to be passed to the custom free function b2FreeFcn. When doing your own allocation tracking getting the original size makes things a lot easier than having to bookkeep the requested sizes yourself. It would be a trivial thing to add to box2d since b2Free already takes the original size itself.
The necessary change would basically amount to the following in base.h:
/// Prototype for user free function
/// @param mem the memory previously allocated through `b2AllocFcn`
/// @param size the original allocation size in bytes
typedef void b2FreeFcn( void* mem, unsigned int size );
and the following within b2Free in core.c:
...
if ( b2_freeFcn != NULL )
{
B2_ASSERT( size > 0 );
unsigned int size32 = ( ( size - 1 ) | 0x1F ) + 1;
b2_freeFcn( mem, size32 );
}
...
Thanks!
Thomas