| Home | Libraries | People | FAQ | More

## Class template fast_pool_allocator

boost::fast_pool_allocator — A C++ Standard Library conforming allocator geared towards allocating single chunks.

## Synopsis

    // In header: <boost/pool/poolfwd.hpp>

    template<typename T,
             typename UserAllocator = default_user_allocator_new_delete,
             typename Mutex = details::pool::default_mutex,
             unsigned NextSize = 32, unsigned MaxSize = 0>
    class fast_pool_allocator {
    public:
      // construct/copy/destruct
      fast_pool_allocator();
      template<typename U>
        fast_pool_allocator(const fast_pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > &);

      // public member functions
      void construct(const pointer, const value_type &);
      void destroy(const pointer);
      bool operator==(const fast_pool_allocator &) const;
      bool operator!=(const fast_pool_allocator &) const;

      // public static functions
      static pointer address(reference);
      static const_pointer address(const_reference);
      static size_type max_size();
      static pointer allocate(const size_type);
      static pointer allocate(const size_type, const void *);
      static pointer allocate();
      static void deallocate(const pointer, const size_type);
      static void deallocate(const pointer);
    };

## Description

While class template `pool_allocator` is a more general-purpose solution geared towards efficiently servicing requests for any number of contiguous chunks, `fast_pool_allocator` is also a general-purpose solution, but is geared towards efficiently servicing requests for one chunk at a time; it will work for contiguous chunks, but not as well as `pool_allocator`.

If you are seriously concerned about performance, use `fast_pool_allocator` when dealing with containers such as `std::list`, and use `pool_allocator` when dealing with containers such as `std::vector`.

The template parameters are defined as follows:

T Type of object to allocate/deallocate.

UserAllocator. Defines the method that the underlying Pool will use to allocate memory from the system. See User Allocators for details.

Mutex Allows the user to determine the type of synchronization to be used on the underlying `singleton_pool`.

NextSize The value of this parameter is passed to the underlying Pool when it is created.

MaxSize Limit on the maximum size used.

| Note
The underlying singleton_pool used by the this allocator constructs a pool instance that is never freed. This means that memory allocated by the allocator can be still used after main() has completed, but may mean that some memory checking programs will complain about leaks.

### `fast_pool_allocator` public construct/copy/destruct

1.     fast_pool_allocator();

   Ensures construction of the underlying `singleton_pool` IFF an instance of this allocator is constructed during global initialization. See ticket #2359 for a complete explanation at http://svn.boost.org/trac/boost/ticket/2359 .

2.     template<typename U>
         fast_pool_allocator(const fast_pool_allocator< U, UserAllocator, Mutex, NextSize, MaxSize > &);

   Ensures construction of the underlying `singleton_pool` IFF an instance of this allocator is constructed during global initialization. See ticket #2359 for a complete explanation at http://svn.boost.org/trac/boost/ticket/2359 .

### `fast_pool_allocator` public member functions

1.     void construct(const pointer ptr, const value_type & t);

2.     void destroy(const pointer ptr);

   Destroy ptr using destructor.

3.     bool operator==(const fast_pool_allocator &) const;

4.     bool operator!=(const fast_pool_allocator &) const;

### `fast_pool_allocator` public static functions

1.     static pointer address(reference r);

2.     static const_pointer address(const_reference s);

3.     static size_type max_size();

4.     static pointer allocate(const size_type n);

5.     static pointer allocate(const size_type n, const void * const);

   Allocate memory .

6.     static pointer allocate();

   Allocate memory.

7.     static void deallocate(const pointer ptr, const size_type n);

   Deallocate memory.

8.     static void deallocate(const pointer ptr);

   deallocate/free