memory management problem (new/delete)

sepul
Posts: 5
Joined: Sun Apr 24, 2011 12:15 pm

memory management problem (new/delete)

Post by sepul »

I have linked bullet with my project, and overrided allocation/deallocation routines as described in documentation
but bullet seems to skip some allocations, because it's using the common new/delete operators. but my engine is overriding those operators and handles them in it's memory manager, so It gets conflicted with bullet and raises memory exceptions.

is there any way to get around this? besides editing bullet code myself ?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: memory management problem (new/delete)

Post by Erwin Coumans »

That should not happen, so it could be a bug. Can you report where it happens?

Thanks,
Erwin
sepul
Posts: 5
Joined: Sun Apr 24, 2011 12:15 pm

Re: memory management problem (new/delete)

Post by sepul »

that's not a bug, actually a design conflict

in my code I have overrided new/delete like below :

Code: Select all

HMR_INLINE void* operator new( hmr::usize sizeBytes, hmr::uint8 alignment, hmr::pcstr filename, hmr::uint32 line, hmr::uint32 groupId )
{
#ifdef HMR_TRACE_MEMORY
	return hmr::mem::AllocAligned( sizeBytes, alignment, filename, line, groupId );
#else
	return malloc(sizeBytes);
#endif
}

HMR_INLINE void operator delete( void* ptr )
{
#ifdef HMR_TRACE_MEMORY
	hmr::mem::FreeAligned( ptr );
#else
	free(ptr);
#endif
}
where I get some extra parameters for memory Id, tracing, etc. things I need for memory management
in your code you are using simple new/delete operators, where 'new' is called within C++ default namespace and 'delete' is called through my routine. this is where I get exceptions.

I'm thinking of something to get away with this the cleanest way possible , what do you think I should do ?
although it would be nice if your code could redirect new/deletes to btAlloc, btFree and use indirect pointer for new operator.

thanks
sepul
Posts: 5
Joined: Sun Apr 24, 2011 12:15 pm

Re: memory management problem (new/delete)

Post by sepul »

I've fixed it in my program, it was more of a bug in my program actually

sorry.