#include <Corrade/Containers/GrowableArray.h>
template<class T>
ArrayAllocator struct new in 2020.06
Allocator for growable arrays.
Is either ArrayMallocAllocator for trivially copyable T
, or ArrayNewAllocator otherwise, in which case reallocation operations expect T
to be nothrow move-constructible.
See Growable arrays for an introduction to growable arrays.
You can provide your own allocator by implementing a class that with Type, allocate(), reallocate(), deallocate(), grow(), capacity(), base() and deleter() following the documented semantics.
Public types
- using Type = T
Public static functions
-
static auto allocate(std::
size_t capacity) -> T* - Allocate (but not construct) an array of given capacity.
-
static void reallocate(T*& array,
std::
size_t prevSize, std:: size_t newCapacity) - Reallocate an array to given capacity.
- static void deallocate(T* data)
- Deallocate (but not destruct) an array.
-
static auto grow(T* array,
std::
size_t desired) -> std:: size_t - Grow an array.
-
static auto capacity(T* array) -> std::
size_t - Array capacity.
- static auto base(T* array) -> void*
- Array base address.
-
static void deleter(T* data,
std::
size_t size) - Array deleter.
Typedef documentation
template<class T>
typedef T Corrade:: Containers:: ArrayAllocator<T>:: Type
Pointer type
Function documentation
template<class T>
static T* Corrade:: Containers:: ArrayAllocator<T>:: allocate(std:: size_t capacity)
Allocate (but not construct) an array of given capacity.
Implementations are expected to store the capacity
in a way that makes it possible to retrieve it later via capacity().
template<class T>
static void Corrade:: Containers:: ArrayAllocator<T>:: reallocate(T*& array,
std:: size_t prevSize,
std:: size_t newCapacity)
Reallocate an array to given capacity.
Assumes array
was returned earlier by allocate() or reallocate(). Implementations are expected to either extend array
in-place to newCapacity
or allocate a new array with newCapacity
, move prevSize
elements from array
to it and call destructors on their original location, deallocate the array
and update the reference to point to the new memory.
template<class T>
static void Corrade:: Containers:: ArrayAllocator<T>:: deallocate(T* data)
Deallocate (but not destruct) an array.
Assumes that data
was returned earlier by allocate() or reallocate(). Implementations are expected to free all memory associated with data
.
template<class T>
static std:: size_t Corrade:: Containers:: ArrayAllocator<T>:: grow(T* array,
std:: size_t desired)
Grow an array.
Assumes that array
is either nullptr
or was returned earlier by allocate() or reallocate(). Implementations are expected to return a new capacity with an an optimal tradeoff between reallocation count and memory usage, the value then being passed to reallocate().
See documentation of a particular implementation (such as ArrayNewAllocator::
template<class T>
static std:: size_t Corrade:: Containers:: ArrayAllocator<T>:: capacity(T* array)
Array capacity.
Implementations are expected to retrieve the capacity information from array
.
template<class T>
static void* Corrade:: Containers:: ArrayAllocator<T>:: base(T* array)
Array base address.
Returns base address of the allocation backing array
. For use by Address Sanitizer to annotate which area of the allocation is safe to access and which not.
template<class T>
static void Corrade:: Containers:: ArrayAllocator<T>:: deleter(T* data,
std:: size_t size)
Array deleter.
Passed as a function pointer into Array. Calls destructors on size
elements and delegates into deallocate(). The deleter function pointer is used to distinguish if given array is using this particular allocator — you might want to turn this function into an exported symbol when growing arrays across shared library boundaries to avoid each library thinking it's using some other allocator and reallocating on each addition.