Hello, <snip />
Why is *object_pool* acting like this and is there a way to change the behavior?****
PS! The threshold value is not exactly the same in another application I have made, but it is pretty close.
This is an "amortized constant time" optimization. i.e. object pools allocates many object at once everytime it's full. The ratio is exponential (allocates twice the memory each time). This allows very fast inserts most of the time. It is much faster than allocating new memory each time. STL containers (vector...) use the same approach. Vendors may change the ratio (i.e. Microsoft uses 1.5 instead of 2). If you add more elements to your pool, it will not grow. Sadly, object_pool seems to be missing a constructor taking a size as a parameter to avoid that kind of problems (but there maybe another way around it I am not aware of). I guess that object_pool is _not_ optimized to minimize memory usage, but to minimize the number of heap allocations (that are very slow). Here is a link to give you more info: http://matetelki.com/blog/?p=114 Regards, Julien