Open 3D Engine SurfaceData Gem API Reference 26.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
SurfaceData::mixed_stack_heap_allocator< Node, NumNodes > Struct Template Reference

#include <MixedStackHeapAllocator.h>

Public Member Functions

 AZ_TYPE_INFO (mixed_stack_heap_allocator, "{49B6706B-716F-42F2-92CB-7FD1A57BE2F9}")
 
 mixed_stack_heap_allocator (const mixed_stack_heap_allocator &rhs)
 
mixed_stack_heap_allocator & operator= (const mixed_stack_heap_allocator &rhs)
 
pointer allocate (size_type byteSize, size_type alignment, int flags=0)
 
void deallocate (pointer ptr, size_type byteSize, size_type alignment)
 
pointer reallocate (pointer ptr, size_type newSize, align_type newAlignment=1) const
 
size_type max_size () const
 
size_type NumAllocatedBytes () const
 
constexpr bool is_lock_free () const
 
constexpr bool is_stale_read_allowed () const
 
constexpr bool is_delayed_recycling () const
 

Friends

bool operator== (const mixed_stack_heap_allocator &a, const mixed_stack_heap_allocator &b)
 

Detailed Description

template<class Node, size_t NumNodes>
struct SurfaceData::mixed_stack_heap_allocator< Node, NumNodes >

mixed_stack_heap_allocator

This allocator is a hybrid between a stack-based allocator and a heap-based allocator. It is intended for use with vector<> as a way to get the performance of fixed_vector<> when few nodes are needed, while still retaining the flexibility of general-purpose resizing when a large number of nodes are needed.

In particular, this is useful for APIs that use a temporary vector<> during processing that is sized based on an input to the API, and the APIs have different use cases that could significantly vary the size requirements.

Usage: vector<T, mixed_stack_heap_allocator<T, N>> tempData;

This will create a vector<T> that pre-allocates space for N nodes on the stack. If the vector attempts to allocate N entries or less, the allocation will come from the stack space. If more than N entries are allocated, or if the vector attempts to grow beyond N entries, the memory will instead come from the heap.

Limitations:

  • This currently only supports exactly one allocation from the stack, which works well for vector<>, but may not work as well for other data types.
  • Once the memory is allocated from the heap, shrinking the allocation won't cause it to use the stack unless the vector<> is fully deallocated and reallocated.

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