more on memory issues with the library.

Post Reply
podfish
Posts: 6
Joined: Wed Oct 10, 2012 12:38 am

more on memory issues with the library.

Post by podfish »

Is there any documentation or centralized information on the memory-use philosophies behind the bullet libraries?

I've found several threads, going back a few years, where it's discussed. The 'btAlignedXXX' system, including the setCustom functions, seems to be the core of bullet's memory use. The BT_DECLARE_ALIGNED_ALLOCATOR macro seems to be the way that classes are defined to use this memory subsystem. However, it doesn't seem to be universally applied - lots of classes don't use it.
There is also a discussion about smart-pointers and order-of-release issues, where it's pointed out that it's the user's responsibility to control the sequence where objects are created and destroyed.

My understanding is that the source code in the 'Extras' and 'Demos' folders isn't as fully developed as the main source, but I was surprised to find that some objects (e.g. the btDefaultCollisionConstructionInfo object) in the 'src' folders don't use the btAligned system. Is there an intent to make the use of btAligned memory allocations universal throughout the library?

Hasn't this been an issue for other users? Are most of you just using ::operator-new instead of controlling all memory with a pool system, or do you modify the bullet libraries when needed?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: more on memory issues with the library.

Post by Erwin Coumans »

The original introduction of BT_DECLARE_ALIGNED_ALLOCATOR was to make sure that instances of certain classes are 16-byte aligned. Not all instances need to be aligned.

There is no discussion about 'smart pointers' etc, Bullet is not using them, and won't use them in the future. Object ownership is explicit, and the rule is "who create the object will destroy it".

All _internal_ allocations should go through the memory allocator, and not using new/delete. If you are allocating objects yourself, you need to make sure it goes through the allocator.
One easy way is to use btAlignedObjectArray, or using btAlignedAlloc/Free manually.

There are no major API changes planned for Bullet 2.x, but we can reconsider how to improve this for Bullet 3.x.
Thanks for the feedback!
Erwin
podfish
Posts: 6
Joined: Wed Oct 10, 2012 12:38 am

Re: more on memory issues with the library.

Post by podfish »

Erwin Coumans wrote:..All _internal_ allocations should go through the memory allocator, and not using new/delete. If you are allocating objects yourself, you need to make sure it goes through the allocator.
One easy way is to use btAlignedObjectArray, or using btAlignedAlloc/Free manually.
that's the heart of my question. I found that the code distributed in the Extras/Serialize folder does indeed use global operator-new.

Since we can't do that on our engine, I've reworked it so that it instead gets memory via btAlignedAlloc/Free. I haven't yet found out how to submit proposed changes to this site; when I figure it out, I'll post my my code so you can see if it's worth incorporating in a later release.
Post Reply