Sharing BufferPool across Simulations and other consumers #129
-
Hello! I'm (finally) integrating BEPUv2 with our engine and I've been poking around to see how it's put together (I really like the design by the way, especially with low level access with higher level helpers on top, it's something I've been using as general principle as well) and there's one thing (well more, but not ready to ask others yet xD ) that I'm uncertain about. Is it ok to share BufferPool across different consumers? In my usecase there will be multiple Simulations in parallel and I plan on using some of the "internal" structures like Tree in isolation as well, which also seems to consume BufferPool. It would be accessed from multiple threads in parallel as well. I'm not sure if having a single instance of BufferPool for everything is a good idea or not performance wise (assuming everything using it is properly disposed to free up resources of course), or whether it would even work, e.g. is it fully thread safe or would I end up corrupting it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Glad you're liking it! The bad news is that using a The good news is that having multiple Notably, the cost of allocation and deallocation is constant regardless of allocation counts, so there won't be any impact on runtime performance either way. |
Beta Was this translation helpful? Give feedback.
Glad you're liking it!
The bad news is that using a
BufferPool
simultaneously on multiple threads will indeed corrupt it- it does not provide any kind of thread safety.The good news is that having multiple
BufferPools
is totally fine. Only potential concern would be a little bit of memory capacity waste if the pools are used for a few tiny allocations, since the backing allocations are going to be fairly large by default. You can give a smaller block size to the constructor to help with that if it's an issue. (That kind of use case would also benefit from moving theBufferPool
from LOH allocations to POH or native allocations, which is on the todo list and is very easy to do.)Notably, t…