struct
allocatorThe default allocator used by soagen tables.
Customizing allocators for soagen
Custom allocators may implement two soagen-specific extensions relating to memory alignment to assist the compiler with generating performant code. These are detailed below.
Specifying a min_alignment
If you know that your allocator will never align allocations on a boundary smaller than a particular value (say, 64 bytes), you can make soagen aware of this by adding a constexpr constant called min_alignment
. Example:
struct my_allocator { inline constexpr std::size_t min_alignment = 64; }
Soagen will then propagate this information to the tables where it may be of use to the compiler.
Providing an alignment-aware allocate()
If your environment has some aligned-allocation facility you wish to make soagen aware of, you can do so by providing an alignment-aware overload of allocate()
taking a std::
for alignment:
struct my_allocator { value_type* allocate(std::size_t size, std::align_val_t alignment) { return my_aligned_alloc_function(size, static_cast<std::size_t>(alignment)); } }
Soagen will choose this overload over any others if it is present.
Public types
-
using is_always_equal = std::
true_type - Instances of this allocator are always equal.
-
using propagate_on_container_copy_assignment = std::
false_type - Instances of this allocator don't propagate on copy-assignment.
-
using propagate_on_container_move_assignment = std::
false_type - Instances of this allocator don't propagate on move-assignment.
-
using propagate_on_container_swap = std::
false_type - Instances of this allocator don't propagate on swap.
-
using value_type = std::
byte - The value type allocated by this allocator.
Public static variables
-
static size_
type min_alignment constexpr - The minimum alignment of any allocations created by this allocator.
Public functions
-
auto allocate(size_
type size, std:: align_val_t alignment = std:: align_val_t{ min_ alignment }) → value_ type* - Alignment-aware allocation.
-
void deallocate(value_
type* ptr, ] size_ type size) noexcept - Deallocation.
Friends
- auto operator!=(const allocator&, const allocator&) → bool noexcept
- Inequality operator.
- auto operator==(const allocator&, const allocator&) → bool noexcept
- Equality operator.
Function documentation
value_ type* soagen:: allocator:: allocate(size_ type size,
std:: align_val_t alignment = std:: align_val_t{ min_ alignment })
Alignment-aware allocation.
Parameters | |
---|---|
size | The size of the allocation, in bytes. |
alignment | The minimum alignment, in bytes. Must be a power-of-two. |
Returns | A new allocation. |
Exceptions | |
std:: |
If the system aligned-allocation function failed. |
void soagen:: allocator:: deallocate(value_ type* ptr,
] size_ type size) noexcept
Deallocation.
Parameters | |
---|---|
ptr | The pointer to the memory being deallocated. Must have been acquired via allocate(). |
size | The size of the allocation, in bytes. Must be the value used for previous call to allocate(). |