When should one prefer object pool over dynamically allocated objects?
I need to create and destroy thousands of objects per second. Is it by itself enough to decide in favor of object pool?
Thanks.
Advantage of Object Pool design patternIt is most effective in a situation where the rate of initializing a class instance is high. It manages the connections and provides a way to reuse and share them. It can also provide the limit for the maximum number of objects that can be created.
What Does Object Pooling Mean? Object pooling is an automatic service that allows a pool of active component instances to be maintained for usage by any requesting client. Object pooling provides a repository of active and ready-made objects that may be used by clients requesting configured pooling components.
Benefits. Object pooling can offer a significant performance boost in situations where the cost of initializing a class instance is high and the rate of instantiation and destruction of a class is high – in this case objects can frequently be reused, and each reuse saves a significant amount of time.
Yes, this is enough to decide in favor of object pool.
Quoting Boost documentation
When should I use Pool?
Pools are generally used when there is a lot of allocation and deallocation of small objects. Another common usage is the situation above, where many objects may be dropped out of memory.
See Boost Pool library
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With