Object pool vs. dynamic allocation

jackhab picture jackhab · Aug 9, 2009 · Viewed 9.9k times · Source

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.

Answer

Diaa Sami picture Diaa Sami · Aug 9, 2009

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