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 for the latest Boost documentation.
PrevUpHomeNext

Class template aligned_allocator

boost::alignment::aligned_allocator

Synopsis

// In header: <boost/align/aligned_allocator.hpp>

template<typename T, std::size_t Alignment> 
class aligned_allocator {
public:
  // types
  typedef T              value_type;        
  typedef T *            pointer;           
  typedef const T *      const_pointer;     
  typedef void *         void_pointer;      
  typedef const void *   const_void_pointer;
  typedef std::size_t    size_type;         
  typedef std::ptrdiff_t difference_type;   
  typedef T &            reference;         
  typedef const T &      const_reference;   

  // member classes/structs/unions
  template<typename U> 
  struct rebind {
    // types
    typedef aligned_allocator< U, Alignment > other;
  };

  // construct/copy/destruct
  aligned_allocator();
  template<typename U> 
    aligned_allocator(const aligned_allocator< U, Alignment > &) noexcept;

  // public member functions
  pointer address(reference) const noexcept;
  const_pointer address(const_reference) const noexcept;
  pointer allocate(size_type, const_void_pointer = 0);
  void deallocate(pointer, size_type);
  BOOST_CONSTEXPR size_type max_size() const noexcept;
  template<typename U, class... Args> void construct(U *, Args &&...);
  template<typename U> void construct(U *);
  template<typename U> void destroy(U *);
};

Description

Class template aligned_allocator.

Note: Except for the destructor, member functions of the aligned allocator shall not introduce data races as a result of concurrent calls to those member functions from different threads. Calls to these functions that allocate or deallocate a particular unit of storage shall occur in a single total order, and each such deallocation call shall happen before the next allocation (if any) in this order.

[Note] Note

Specifying minimum alignment is generally only suitable for containers such as vector and undesirable with other, node-based, containers. For node-based containers, such as list, the node object would have the minimum alignment specified instead of the value type object.

Template Parameters

  1. typename T
  2. std::size_t Alignment

    Is the minimum alignment to specify for allocations, if it is larger than the alignment of the value type. It shall be a power of two.

aligned_allocator public construct/copy/destruct

  1. aligned_allocator();
  2. template<typename U> 
      aligned_allocator(const aligned_allocator< U, Alignment > &) noexcept;

aligned_allocator public member functions

  1. pointer address(reference value) const noexcept;

    Returns:

    The actual address of the object referenced by value, even in the presence of an overloaded operator&.

  2. const_pointer address(const_reference value) const noexcept;

    Returns:

    The actual address of the object referenced by value, even in the presence of an overloaded operator&.

  3. pointer allocate(size_type size, const_void_pointer = 0);

    Throw: Throws std::bad_alloc if the storage cannot be obtained.

    Note: The storage is obtained by calling aligned_alloc(std::size_t, std::size_t).

    Returns:

    A pointer to the initial element of an array of storage of size n * sizeof(T), aligned on the maximum of the minimum alignment specified and the alignment of objects of type T.

  4. void deallocate(pointer ptr, size_type);

    Deallocates the storage referenced by ptr.

    Note: Uses alignment::aligned_free(void*).

    Parameters:

    ptr

    Shall be a pointer value obtained from allocate().

  5. BOOST_CONSTEXPR size_type max_size() const noexcept;

    Returns:

    The largest value N for which the call allocate(N) might succeed.

  6. template<typename U, class... Args> void construct(U * ptr, Args &&... args);

    Calls global new((void*)ptr) U(std::forward<Args>(args)...).

  7. template<typename U> void construct(U * ptr);

    Calls global new((void*)ptr) U().

  8. template<typename U> void destroy(U * ptr);

    Calls ptr->~U().


PrevUpHomeNext