Pools

Discuss topics related to BEPUphysics or physics engine development.
Post Reply
lidgren
Posts: 21
Joined: Mon May 27, 2019 6:28 pm

Pools

Post by lidgren » Fri Feb 28, 2020 3:12 pm

Is there any documentation or guidelines on how to use pools? I've just been stuffing shapes etc into the same pool I created the simulation with. Is this fine/recommended/frownedupon/madness?

--michael

Norbo
Site Admin
Posts: 4884
Joined: Tue Jul 04, 2006 4:45 am

Re: Pools

Post by Norbo » Fri Feb 28, 2020 7:42 pm

Using the same pool for simulation and shapes in the simulation is fine, and probably best. Tracking which pool to use for disposing shapes could get annoying otherwise, and maximizing the use of one pool improves memory efficiency. (Pools preallocate blocks of memory, so if you have a bunch of pools that each have only a few allocations from them, most of the preallocated space is wasted.)

General recommendations would look like:
1) Use one pool unless there is a reason not to, but
2) having more pools than strictly necessary isn't really a problem. If it would be convenient to create a BufferPool for a side system that manages its own resource lifespans, that's totally fine.
3) BufferPools aren't thread safe.
4) When using thread local buffer pools (like the IThreadDispatcher's API), it can end up being convenient to treat all allocations as living only as long as the thread's execution. This can help avoid complex ownership tracking where it's no longer clear what pool owns what. It's also likely that the engine's own use of thread local memory pools through the IThreadDispatcher will change to region allocators eventually.

lidgren
Posts: 21
Joined: Mon May 27, 2019 6:28 pm

Re: Pools

Post by lidgren » Wed Mar 11, 2020 2:11 pm

Makes sense; I will stick to one pool until perhaps I start looking into unloading distinct parts of the world; maybe then creating spatially oriented pools to put terrain physics data into for example. Thanks for the explanation!

Post Reply