Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Object pool vs. dynamic allocation

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.

like image 806
jackhab Avatar asked Aug 09 '09 09:08

jackhab


People also ask

What is the advantage of object pool design pattern?

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 is the meaning of object pooling?

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.

What is the benefit of object pooling?

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.


1 Answers

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

like image 68
Diaa Sami Avatar answered Sep 25 '22 00:09

Diaa Sami