C++ Boost

pool_alloc - Boost Pool Standard Allocators Implementation

Dependencies

Includes the system headers <new> and <limits>.

Includes the Boost headers "singleton_pool.hpp" (see singleton_pool.html) and "detail/mutex.hpp" (see mutex.html).

Synopsis

template <typename T,
    typename UserAllocator = default_user_allocator_new_delete,
    typename Mutex = details::pool::default_mutex,
    unsigned NextSize = 32>
class pool_allocator
{
  public:
    ... // public interface

  public: // extensions to public interface
    typedef Mutex mutex;
    static const unsigned next_size = NextSize;

    template <typename U>
    struct rebind
    {
      typedef pool_allocator<U, UserAllocator, Mutex, NextSize> other;
    };
};

template <typename T,
    typename UserAllocator = default_user_allocator_new_delete,
    typename Mutex = details::pool::default_mutex,
    unsigned NextSize = 32>
class fast_pool_allocator
{
  public:
    ... // public interface

  public: // extensions to public interface
    typedef Mutex mutex;
    static const unsigned next_size = NextSize;

    template <typename U>
    struct rebind
    {
      typedef fast_pool_allocator<U, UserAllocator, Mutex, NextSize> other;
    };
};

Extensions to Public Interface

Additional template parameters

Mutex

This parameter allows the user to determine the type of synchronization to be used on the underlying singleton pool. See the extensions to the public interface of singleton pool for more information.

NextSize

The value of this parameter is passed to the underlying Pool when it is created. See the extensions to the public interface of pool for more information.

Modification of rebind

The struct rebind has been redefined to preserve the values of the additional template parameters.

Additional members

The typedef mutex and the static const value next_size publish the values of the template parameters Mutex and NextSize, respectively.

Notes

A number of common STL libraries contain bugs in their using of allocators. Specifically, they pass null pointers to the deallocate function, which is explicitly forbidden by the Standard [20.1.5 Table 32]. PoolAlloc will work around these libraries if it detects them; currently, workarounds are in place for:

Future Directions

When the Boost multithreading library is completed, the Mutex parameter will be replaced by something from that library providing the same flexibility and will move from an implementation detail into the interface specification.

Interface Description


Copyright © 2000, 2001 Stephen Cleary (scleary AT jerviswebb DOT com)

This file can be redistributed and/or modified under the terms found in copyright.html

This software and its documentation is provided "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.