Boost C++ Libraries Home Libraries People FAQ More

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> 
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, dtl::alignment_of< T >::value > 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< constT >::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;                               
  typedef dtl::false_type                                                                                                            propagate_on_container_copy_assignment;
  typedef dtl::true_type                                                                                                             propagate_on_container_move_assignment;
  typedef dtl::true_type                                                                                                             propagate_on_container_swap;           
  typedef dtl::false_type                                                                                                            is_always_equal;                       

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

  // public member functions
  private_adaptive_pool() noexcept;
  private_adaptive_pool(const private_adaptive_pool &) noexcept;
  private_adaptive_pool(private_adaptive_pool &&) noexcept;
  private_adaptive_pool & operator=(const private_adaptive_pool &) noexcept;
  private_adaptive_pool & operator=(private_adaptive_pool &&) noexcept;
  template<typename T2> 
    private_adaptive_pool(const private_adaptive_pool< T2, NodesPerBlock, MaxFreeBlocks, OverheadPercent > &) noexcept;
  ~private_adaptive_pool() noexcept;
  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
  void swap(private_adaptive_pool &, private_adaptive_pool &) noexcept;
  bool operator==(const private_adaptive_pool &, 
                  const private_adaptive_pool &) noexcept;
  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
  BOOST_STATIC_CONSTEXPR std::size_t nodes_per_block;
  BOOST_STATIC_CONSTEXPR std::size_t max_free_blocks;
  BOOST_STATIC_CONSTEXPR std::size_t overhead_percent;
  BOOST_STATIC_CONSTEXPR std::size_t real_nodes_per_block;
  pool_t m_pool;
};

Description

An adaptive_pool-like allocator whose node pool is owned by the allocator object, not shared with other instances.

  • A copy (copy constructor, conversion from a rebound allocator, select_on_container_copy_construction) has a new, empty pool, so a copy does not compare equal to the original.

  • Moving or swapping an allocator transfers its pool. Containers propagate the allocator on move assignment and swap (propagate_on_container_move_assignment and propagate_on_container_swap are true), so the nodes stay with the pool that allocated them.

  • Two allocators compare equal only if they are the same object.

Arrays (allocate with count > 1, or any allocation for Version 2) are allocated from the shared dlmalloc heap, so they do not depend on the pool.

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.

  2. typedef dtl::false_type propagate_on_container_copy_assignment;

    The pool moves with the allocator, so the containers must propagate the allocator when they move or swap their nodes

private_adaptive_pool public member functions

  1. private_adaptive_pool() noexcept;
    Default constructor.
  2. private_adaptive_pool(const private_adaptive_pool &) noexcept;
    Copy constructor: the new allocator has a new, empty pool.
  3. private_adaptive_pool(private_adaptive_pool && x) noexcept;
    Move constructor: the new allocator takes the pool of x, and x gets a new, empty pool.
  4. private_adaptive_pool & operator=(const private_adaptive_pool &) noexcept;
    Copy assignment: *this keeps its pool.
  5. private_adaptive_pool & operator=(private_adaptive_pool && x) noexcept;

    Move assignment: the pools are swapped. The nodes of the old pool of *this must have been deallocated before (containers do it before they propagate the allocator)

  6. template<typename T2> 
      private_adaptive_pool(const private_adaptive_pool< T2, NodesPerBlock, MaxFreeBlocks, OverheadPercent > &) noexcept;
    Copy constructor from related private_adaptive_pool: the new allocator has a new, empty pool.
  7. ~private_adaptive_pool() noexcept;
    Destructor.
  8. size_type max_size() const noexcept;

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

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

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

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

    Deallocate allocated memory. Never throws

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

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

  13. 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

  14. 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()

  15. 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

  16. void deallocate_individual(multiallocation_chain & chain) noexcept;
  17. 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()

  18. 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()

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

private_adaptive_pool friend functions

  1. void swap(private_adaptive_pool & l, private_adaptive_pool & r) noexcept;
    Swaps the pools of the allocators. Does not throw.
  2. bool operator==(const private_adaptive_pool & l, 
                    const private_adaptive_pool & r) noexcept;

    Two allocators compare equal only if they are the same object: memory allocated by one pool can't be deallocated by another pool

  3. bool operator!=(const private_adaptive_pool & l, 
                    const private_adaptive_pool & r) noexcept;
    Returns !(l == r)

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