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 the documentation for an old version of Boost. Click here to view this page for the latest version.
PrevUpHomeNext

Class template private_adaptive_pool

boost::container::private_adaptive_pool

Synopsis

// In header: <boost/container/adaptive_pool.hpp>

template<typename T, std::size_t NodesPerBlock = ADP_nodes_per_block, 
         std::size_t MaxFreeBlocks = ADP_max_free_blocks, 
         std::size_t OverheadPercent = ADP_overhead_percent, 
         unsigned Version = 2> 
class private_adaptive_pool {
public:
  // types
  typedef unsigned int                                                                                allocation_type;
  typedef private_adaptive_pool< T, NodesPerBlock, MaxFreeBlocks, OverheadPercent >                   self_t;         
  typedef dtl::private_adaptive_node_pool< sizeof(T), NodesPerBlock, MaxFreeBlocks, OverheadPercent > pool_t;         
  typedef T                                                                                           value_type;     
  typedef T *                                                                                         pointer;        
  typedef const T *                                                                                   const_pointer;  
  typedef ::boost::container::dtl::unvoid_ref< T >::type                                              reference;      
  typedef ::boost::container::dtl::unvoid_ref< const T >::type                                        const_reference;
  typedef std::size_t                                                                                 size_type;      
  typedef std::ptrdiff_t                                                                              difference_type;
  typedef boost::container::dtl::version_type< self_t, Version >                                      version;        

  // member classes/structs/unions
  template<typename T2> 
  struct rebind {
    // types
    typedef private_adaptive_pool< T2, NodesPerBlock, MaxFreeBlocks, OverheadPercent > other;
  };

  // construct/copy/destruct
  private_adaptive_pool() noexcept;
  private_adaptive_pool(const private_adaptive_pool &) noexcept;
  template<typename T2> 
    private_adaptive_pool(const private_adaptive_pool< T2, NodesPerBlock, MaxFreeBlocks, OverheadPercent BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I Version)> &) noexcept;
  ~private_adaptive_pool();

  // public member functions
   BOOST_CONTAINER_DOCIGN(BOOST_STATIC_ASSERT((Version<=2)));
  size_type max_size() const noexcept;
  pointer allocate(size_type, const void * = 0);
  void deallocate(const pointer &, size_type) noexcept;
  pointer allocation_command(allocation_type, size_type, size_type &, 
                             pointer &);
  size_type size(pointer) const noexcept;
  pointer allocate_one();
  void allocate_individual(std::size_t, multiallocation_chain &);
  void deallocate_one(pointer) noexcept;
  void deallocate_individual(multiallocation_chain &) noexcept;
  void allocate_many(size_type, std::size_t, multiallocation_chain &);
  void allocate_many(const size_type *, size_type, multiallocation_chain &);
  void deallocate_many(multiallocation_chain &) noexcept;
  void deallocate_free_blocks() noexcept;

  // friend functions
  friend void swap(private_adaptive_pool &, private_adaptive_pool &) noexcept;
  friend bool operator==(const private_adaptive_pool &, 
                         const private_adaptive_pool &) noexcept;
  friend bool operator!=(const private_adaptive_pool &, 
                         const private_adaptive_pool &) noexcept;

  // private member functions
  pointer priv_allocation_command(allocation_type, std::size_t, size_type &, 
                                  pointer &);

  // public data members
  static const std::size_t nodes_per_block;
  static const std::size_t max_free_blocks;
  static const std::size_t overhead_percent;
  static const std::size_t real_nodes_per_block;
  pool_t m_pool;
};

Description

private_adaptive_pool public types

  1. typedef unsigned int allocation_type;

    If Version is 1, the allocator is a STL conforming allocator. If Version is 2, the allocator offers advanced expand in place and burst allocation capabilities.

private_adaptive_pool public construct/copy/destruct

  1. private_adaptive_pool() noexcept;
    Default constructor.
  2. private_adaptive_pool(const private_adaptive_pool &) noexcept;
    Copy constructor from other private_adaptive_pool.
  3. template<typename T2> 
      private_adaptive_pool(const private_adaptive_pool< T2, NodesPerBlock, MaxFreeBlocks, OverheadPercent BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I Version)> &) noexcept;
    Copy constructor from related private_adaptive_pool.
  4. ~private_adaptive_pool();
    Destructor.

private_adaptive_pool public member functions

  1.  BOOST_CONTAINER_DOCIGN(BOOST_STATIC_ASSERT((Version<=2)));
  2. size_type max_size() const noexcept;

    Returns the number of elements that could be allocated. Never throws

  3. pointer allocate(size_type count, const void * = 0);

    Allocate memory for an array of count elements. Throws std::bad_alloc if there is no enough memory

  4. void deallocate(const pointer & ptr, size_type count) noexcept;

    Deallocate allocated memory. Never throws

  5. pointer allocation_command(allocation_type command, size_type limit_size, 
                               size_type & prefer_in_recvd_out_size, 
                               pointer & reuse);
  6. size_type size(pointer p) const noexcept;

    Returns maximum the number of objects the previously allocated memory pointed by p can hold.

  7. pointer allocate_one();

    Allocates just one object. Memory allocated with this function must be deallocated only with deallocate_one(). Throws bad_alloc if there is no enough memory

  8. void allocate_individual(std::size_t num_elements, 
                             multiallocation_chain & chain);

    Allocates many elements of size == 1. Elements must be individually deallocated with deallocate_one()

  9. void deallocate_one(pointer p) noexcept;

    Deallocates memory previously allocated with allocate_one(). You should never use deallocate_one to deallocate memory allocated with other functions different from allocate_one(). Never throws

  10. void deallocate_individual(multiallocation_chain & chain) noexcept;
  11. void allocate_many(size_type elem_size, std::size_t n_elements, 
                       multiallocation_chain & chain);

    Allocates many elements of size elem_size. Elements must be individually deallocated with deallocate()

  12. void allocate_many(const size_type * elem_sizes, size_type n_elements, 
                       multiallocation_chain & chain);

    Allocates n_elements elements, each one of size elem_sizes[i] Elements must be individually deallocated with deallocate()

  13. void deallocate_many(multiallocation_chain & chain) noexcept;
  14. void deallocate_free_blocks() noexcept;
    Deallocates all free blocks of the pool.

private_adaptive_pool friend functions

  1. friend void swap(private_adaptive_pool &, private_adaptive_pool &) noexcept;

    Swaps allocators. Does not throw. If each allocator is placed in a different memory segment, the result is undefined.

  2. friend bool operator==(const private_adaptive_pool &, 
                           const private_adaptive_pool &) noexcept;

    An allocator always compares to true, as memory allocated with one instance can be deallocated by another instance

  3. friend bool operator!=(const private_adaptive_pool &, 
                           const private_adaptive_pool &) noexcept;

    An allocator always compares to false, as memory allocated with one instance can be deallocated by another instance

private_adaptive_pool private member functions

  1. pointer priv_allocation_command(allocation_type command, 
                                    std::size_t limit_size, 
                                    size_type & prefer_in_recvd_out_size, 
                                    pointer & reuse_ptr);

PrevUpHomeNext