-
-
Notifications
You must be signed in to change notification settings - Fork 314
Stdlib: SingleSizeObjectPool implementation #2360
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
It could be interesting to track:
That would also help testing it for correctness. Secondly, it would be interesting to have a concurrent version of the same. That might be something to consider in the future. |
I'm guessing to keep track of the buffer size and extra nodes (in bytes), right? Also could in theory try to allocate memory once and have it store both the node and the buffer, not sure if I can do something like flexible array member like in C, but then I suppose there will be alignment issues, unless I would align it to
I'm assuming this should also be in bytes?
I'm wondering how this could be done than maybe just protecting it with a mutex? I don't know, maybe some discussion could be had and implemented in the future. |
|
Well, given that we allocate them a slab at a time, we only need to see how many slabs we have created. Then the amount free is the number of elements in the pool. |
|
The simplest way is just protecting it with a mutex. That could be a different implementation, so no need to reuse exactly this one. |
… from "object" to "block"
… from "object" to "block". Support overaligned types. Align blocks directly.
|
Thank you for this. |
Adds Object Pool
SingleSizeObjectPoolto the stdlib, allows users to quickly allocate/reserve objects from the pool and to quickly deallocate/return objects back to the pool, adds modulestd::core::mem::objectpooland tests.Example usage: