On Monday, 12 January 2015 17:42:04 UTC+2, Daniel wrote:
> Consider a third party container that has a template allocator parameter, defaulting to
> std::allocator<void>, and rebinds it as needed when allocating fixed size internal data
> structures.
>
> Now suppose the user of this container decides to apply, for instance, a boost pool_allocator,
Juha Nieminen posted that the particular pool_allocator had terrible performance
in his tests couple of years ago.
https://groups.google.com/forum/#!msg/comp.lang.c++/7HWbMzsMCyc/wDd1tIRj_f0J
I simply avoid using it and works great for me. ;)
> say as
>
> Container<boost::pool_allocator<void>> val;
>
> and proceeds to add many and diverse items into the container.
Notice that it was design decision of *user* of the 'Container' to use some custom (or third
party library) allocator with 'Container'.
>
> At some point, the user is done with the container and wishes to free the memory in the pool,
> but in the case of the boost pool allocator, that requires the user to know about the internal
> data structures in the container, along the lines of
>
> boost::singleton_pool<boost::pool_allocator_tag,
> sizeof(Container::internal_structure1)>::release_memory();
>
> Any suggestions for best practices on the part of the container author for making this
> convenient for the user?
If the user does not know some properties of 'Container' but may need those for something
(like 'sizeof(Container::internal_structure1)') then 'Container's author can provide those
with some 'public static constexpr size_t' in interface of 'Container'.