Orrery
A GPU-accelerated N-body gravitational simulator
Loading...
Searching...
No Matches
orrery::core::AlignedAllocator< T > Class Template Reference

A standard allocator that returns cache-line-aligned storage. More...

#include <orrery/core/aligned_allocator.hpp>

Public Types

using value_type = T
using propagate_on_container_move_assignment = std::true_type
 Moving a container moves its storage rather than copying its elements, which is the behaviour the containers of particle components need.
using is_always_equal = std::true_type
 The allocator holds no state, so any instance can free memory that any other instance allocated.

Public Member Functions

template<typename U>
constexpr AlignedAllocator (const AlignedAllocator< U > &) noexcept
 Containers rebind an allocator to their internal types, so an allocator for one type has to be constructible from an allocator for another.

Static Public Member Functions

static T * allocate (std::size_t count)
 Allocate storage for count objects.
static void deallocate (T *pointer, std::size_t) noexcept
static constexpr std::size_t max_size () noexcept
 The largest count that can be expressed in bytes without wrapping.

Static Public Attributes

static constexpr std::size_t kAlignment = kCacheLineBytes

Detailed Description

template<typename T>
class orrery::core::AlignedAllocator< T >

A standard allocator that returns cache-line-aligned storage.

The alignment is fixed rather than a template parameter. It is one decision about one machine, and it is reviewed here once instead of at every container that could otherwise ask for something different and be wrong without anyone noticing. A fixed alignment also keeps the allocator in the Alloc<T> shape that std::allocator_traits can rebind on its own, so this class needs no rebind member of its own.

Member Function Documentation

◆ allocate()

template<typename T>
T * orrery::core::AlignedAllocator< T >::allocate ( std::size_t count)
inlinestaticnodiscard

Allocate storage for count objects.

Static because the allocator carries no state that allocation could depend on. The standard's allocator requirements are written in terms of the expression a.allocate(n), which a static member satisfies, so containers are unaffected by the distinction.


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