Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is an old version of boost. Click here for the latest version's documentation home page.
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


Valid HTML 4.01 Transitional

Revised 05 December, 2006

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

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)