I'm usinge Bullet physics in an iPhone game. It appears to really be pushing the limits of memory in my iPhone application -- creating an instance of btDefaultCollisionConfiguration appears to allocate ~40 Megabytes of memory. On an iPhone application, that just won't fly. Is there any way to reduce the memory usage of the collision configuration? A different config class or something? Forgive me, I know little about how Bullet functions internally.
Thanks,
- Marcus
Memory usage
-
- Posts: 6
- Joined: Sat Nov 08, 2008 12:50 am
Re: Memory usage
Figured it out.
Usually, when initializing Bullet, there is code that looks something like this:
Changing it to something like this works well:
The defaults for MaxCollision and PersistentManifold pool sizes are 65535 each. When the construction info is set to the above values, memory usage appears to spike to around 8Mb and levels out at around 6Mb in my program which is very simple. That leaves plenty of memory for the rest of my game.
Hope this helps someone.
- Marcus
Usually, when initializing Bullet, there is code that looks something like this:
Code: Select all
collisionConfig = new btDefaultCollisionConfiguration();
Code: Select all
btDefaultCollisionConstructionInfo constructionInfo = btDefaultCollisionConstructionInfo();
constructionInfo.m_defaultMaxCollisionAlgorithmPoolSize = 1023;
constructionInfo.m_defaultMaxPersistentManifoldPoolSize = 1023;
collisionConfig = new btDefaultCollisionConfiguration(constructionInfo);
...
Hope this helps someone.
- Marcus
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Memory usage
Good point.
The default memory pools of Bullet 2.72 were way too big, so your solution is fine. You can also set the stack allocator usage to zero, reducing it by another 2Mb. Note that Bullet automatically switches from pool to dynamic memory allocations, so it is safe to use smaller defaults.
Upcoming Bullet 2.73 has much smaller pools in btDefaultCollisionConstructionInfo:
m_defaultMaxPersistentManifoldPoolSize(4096),
m_defaultMaxCollisionAlgorithmPoolSize(4096),
m_defaultStackAllocatorSize(0)
http://code.google.com/p/bullet/source/detail?r=1482
Thanks for the feedback,
Erwin
The default memory pools of Bullet 2.72 were way too big, so your solution is fine. You can also set the stack allocator usage to zero, reducing it by another 2Mb. Note that Bullet automatically switches from pool to dynamic memory allocations, so it is safe to use smaller defaults.
Upcoming Bullet 2.73 has much smaller pools in btDefaultCollisionConstructionInfo:
m_defaultMaxPersistentManifoldPoolSize(4096),
m_defaultMaxCollisionAlgorithmPoolSize(4096),
m_defaultStackAllocatorSize(0)
http://code.google.com/p/bullet/source/detail?r=1482
Thanks for the feedback,
Erwin
-
- Posts: 508
- Joined: Fri May 30, 2008 2:51 am
- Location: Ossining, New York
Re: Memory usage
I've seen issues about configuring bullet for low memory platforms come up a couple of times, it might be a good idea to write a wiki page about it
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: Memory usage
The new default lower memory pre-allocation will reduce the number of reported issue for iPhone etc.
But we definately need to document how to manage memory in the Wiki, doxygen and Bullet user manual.
Thanks,
Erwin
But we definately need to document how to manage memory in the Wiki, doxygen and Bullet user manual.
Thanks,
Erwin