cds  2.3.2
cds::OS::aligned_allocator< T > Class Template Reference

Aligned allocator. More...

#include <cds/os/alloc_aligned.h>

Data Structures

struct  rebind
 convert an aligned_allocator<T> to an aligned_allocator<OTHER> More...
 

Public Types

typedef prototype::value_type value_type
 value type
 
typedef prototype::pointer pointer
 pointer to value type
 
typedef prototype::reference reference
 value reference type
 
typedef prototype::const_pointer const_pointer
 const pointer to value type
 
typedef prototype::const_reference const_reference
 const value reference type
 
typedef prototype::size_type size_type
 size type
 
typedef prototype::difference_type difference_type
 difference type
 

Public Member Functions

pointer address (reference v) const
 return address of mutable v
 
const_pointer address (const_reference v) const
 return address of nonmutable v
 
 aligned_allocator (const aligned_allocator< T > &) noexcept
 construct by copying (do nothing)
 
template<class OTHER >
 aligned_allocator (const aligned_allocator< OTHER > &) noexcept
 construct from a related allocator (do nothing)
 
template<class OTHER >
aligned_allocator< T > & operator= (const aligned_allocator< OTHER > &)
 assign from a related allocator (do nothing)
 
void deallocate (pointer ptr, size_type)
 deallocate object at ptr, ignore size
 
pointer allocate (size_type nAlign, size_type nCount)
 allocate array of nCount elements More...
 
pointer allocate (size_type nAlign, size_type nCount, const void *)
 allocate array of nCount elements, ignore hint More...
 
void construct (pointer ptr, const T &val)
 construct object at ptr with value val
 
void destroy (pointer ptr)
 destroy object at ptr
 
size_type max_size () const noexcept
 estimate maximum array size
 

Private Types

typedef std::allocator< T > prototype
 prototype (the source of typedefs)
 

Detailed Description

template<typename T>
class cds::OS::aligned_allocator< T >

Aligned allocator.

This allocator is intended for allocating of an aligned memory block. It uses wrappers around platform-specific function for allocating and deallocating the block of memory:

  • aligned_malloc for allocating
  • aligned_free for deallocating

The aligned_malloc function wraps:

  • for Win: _aligned_malloc function
  • for other OSes: posix_memalign / memalign function

The aligned_free function wraps:

  • for Win: _aligned_free function
  • for other OSes: free function

This class should not be used directly. Use cds::details::AlignedAllocator instead.

Member Function Documentation

◆ allocate() [1/2]

template<typename T >
pointer cds::OS::aligned_allocator< T >::allocate ( size_type  nAlign,
size_type  nCount 
)
inline

allocate array of nCount elements

The address returned is aligned by nAlign boundary. nAlign parameter should be power of 2.

The function guarantees the alignment for first element of array only. To guarantee the alignment for each element of the array the size of an object of type T must be multiple of nAlign:

sizeof(T) % nAlign == 0

The function, like operator new does not return nullptr. In no memory situation the function throws std::bad_alloc exception.

◆ allocate() [2/2]

template<typename T >
pointer cds::OS::aligned_allocator< T >::allocate ( size_type  nAlign,
size_type  nCount,
const void *   
)
inline

allocate array of nCount elements, ignore hint

The address returned is aligned by nAlign boundary. nAlign parameter should be power of 2.

The function guarantees alignment for first element of array only.


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

cds 2.3.2 Developed by Maxim Khizhinsky aka khizmax and other contributors 2007 - 2017
Autogenerated Sun Dec 31 2017 12:10:52 by Doxygen 1.8.13