proxygen
folly::AlignedSysAllocator< T, Align > Class Template Reference

#include <Memory.h>

Inheritance diagram for folly::AlignedSysAllocator< T, Align >:

Public Types

using value_type = T
 
using propagate_on_container_copy_assignment = std::true_type
 
using propagate_on_container_move_assignment = std::true_type
 
using propagate_on_container_swap = std::true_type
 

Public Member Functions

template<typename S = Align, _t< std::enable_if< std::is_default_constructible< S >::value, int >> = 0>
constexpr AlignedSysAllocator () noexcept(noexcept(Align()))
 
template<typename U >
constexpr AlignedSysAllocator (AlignedSysAllocator< U, Align > const &other) noexcept
 
Tallocate (size_t count)
 
void deallocate (T *p, size_t)
 

Private Types

using Self = AlignedSysAllocator< T, Align >
 

Private Member Functions

constexpr Align const & align () const
 

Friends

template<typename , typename >
class AlignedSysAllocator
 
bool operator== (Self const &a, Self const &b) noexcept
 
bool operator!= (Self const &a, Self const &b) noexcept
 

Detailed Description

template<typename T, typename Align = DefaultAlign>
class folly::AlignedSysAllocator< T, Align >

AlignedSysAllocator

Resembles std::allocator, the default Allocator, but wraps aligned_malloc and aligned_free.

Accepts a policy parameter for providing the alignment, which must:

  • be invocable as std::size_t() noexcept, returning the alignment
  • be noexcept-copy-constructible
  • have noexcept operator==
  • have noexcept operator!=
  • not be final

DefaultAlign and FixedAlign<std::size_t>, provided above, are valid policies.

Definition at line 453 of file Memory.h.

Member Typedef Documentation

template<typename T, typename Align = DefaultAlign>
using folly::AlignedSysAllocator< T, Align >::propagate_on_container_copy_assignment = std::true_type

Definition at line 470 of file Memory.h.

template<typename T, typename Align = DefaultAlign>
using folly::AlignedSysAllocator< T, Align >::propagate_on_container_move_assignment = std::true_type

Definition at line 471 of file Memory.h.

template<typename T, typename Align = DefaultAlign>
using folly::AlignedSysAllocator< T, Align >::propagate_on_container_swap = std::true_type

Definition at line 472 of file Memory.h.

template<typename T, typename Align = DefaultAlign>
using folly::AlignedSysAllocator< T, Align >::Self = AlignedSysAllocator<T, Align>
private

Definition at line 455 of file Memory.h.

template<typename T, typename Align = DefaultAlign>
using folly::AlignedSysAllocator< T, Align >::value_type = T

Definition at line 468 of file Memory.h.

Constructor & Destructor Documentation

template<typename T, typename Align = DefaultAlign>
template<typename S = Align, _t< std::enable_if< std::is_default_constructible< S >::value, int >> = 0>
constexpr folly::AlignedSysAllocator< T, Align >::AlignedSysAllocator ( )
inlinenoexcept

Definition at line 480 of file Memory.h.

480 : Align() {}
template<typename T, typename Align = DefaultAlign>
template<typename U >
constexpr folly::AlignedSysAllocator< T, Align >::AlignedSysAllocator ( AlignedSysAllocator< U, Align > const &  other)
inlineexplicitnoexcept

Definition at line 483 of file Memory.h.

485  : Align(other.align()) {}

Member Function Documentation

template<typename T, typename Align = DefaultAlign>
constexpr Align const& folly::AlignedSysAllocator< T, Align >::align ( ) const
inlineprivate

Definition at line 460 of file Memory.h.

References value.

460  {
461  return *this;
462  }
template<typename T, typename Align = DefaultAlign>
T* folly::AlignedSysAllocator< T, Align >::allocate ( size_t  count)
inline

Definition at line 487 of file Memory.h.

References folly::aligned_malloc(), FOLLY_UNLIKELY, and folly::T.

487  {
488  using lifted = typename detail::lift_void_to_char<T>::type;
489  auto const p = aligned_malloc(sizeof(lifted) * count, align()());
490  if (!p) {
491  if (FOLLY_UNLIKELY(errno != ENOMEM)) {
492  std::terminate();
493  }
494  throw_exception<std::bad_alloc>();
495  }
496  return static_cast<T*>(p);
497  }
#define FOLLY_UNLIKELY(x)
Definition: Likely.h:36
folly::std T
void * aligned_malloc(size_t size, size_t align)
Definition: Memory.h:85
int * count
constexpr Align const & align() const
Definition: Memory.h:460
template<typename T, typename Align = DefaultAlign>
void folly::AlignedSysAllocator< T, Align >::deallocate ( T p,
size_t   
)
inline

Definition at line 498 of file Memory.h.

References folly::aligned_free().

498  {
499  aligned_free(p);
500  }
void aligned_free(void *aligned_ptr)
Definition: Memory.h:89

Friends And Related Function Documentation

template<typename T, typename Align = DefaultAlign>
template<typename , typename >
friend class AlignedSysAllocator
friend

Definition at line 458 of file Memory.h.

template<typename T, typename Align = DefaultAlign>
bool operator!= ( Self const &  a,
Self const &  b 
)
friend

Definition at line 505 of file Memory.h.

505  {
506  return a.align() != b.align();
507  }
char b
char a
template<typename T, typename Align = DefaultAlign>
bool operator== ( Self const &  a,
Self const &  b 
)
friend

Definition at line 502 of file Memory.h.

502  {
503  return a.align() == b.align();
504  }
char b
char a

The documentation for this class was generated from the following file: