geomc 1.0
A c++ linear algebra template library
|
Array storage which does not allocate from the heap unless the requested size is larger than a threshhold, N
.
More...
#include <geomc/Storage.h>
Public Member Functions | |
SmallStorage (index_t n) | |
Allocate storage for n objects. | |
~SmallStorage () | |
Destory this storage. | |
SmallStorage (SmallStorage< T, N > &other) | |
Construct a new SmallStorage containing the elements of other . | |
SmallStorage (const T *array, index_t n) | |
Construct a new SmallStorage containing a copy of the n elements in array . | |
SmallStorage (SmallStorage< T, N > &&other) noexcept | |
Move the contents of other to a new SmallStorage . | |
SmallStorage< T, N > & | operator= (SmallStorage< T, N > &&other) noexcept |
Move the contents of other to this SmallStorage . | |
SmallStorage< T, N > & | operator= (SmallStorage< T, N > &other) |
Copy the contents of other to this SmallStorage . | |
T * | get () |
Return a pointer to the first element in the storage array. | |
const T * | get () const |
Return a pointer to the first (const) element in the storage array. | |
index_t | size () const |
Return the number of elements in the array. | |
T & | operator[] (index_t i) |
Return a reference to the i th element in the array. | |
T | operator[] (index_t i) const |
Return the i th element in the array. | |
void | resize (index_t n) |
Ensure space is available for at least n elements. More... | |
Array storage which does not allocate from the heap unless the requested size is larger than a threshhold, N
.
T | Element type. |
N | Maximum stack-allocated array size. |
Useful when a required buffer is expected to be small, but there is no explicit upper bound on the possible size. This allows the stack to be used in the majority case, only deferring to heap allocation when unusually large buffers are needed.
On assignment or copy, reallocations will be avoided if the existing buffer is already the correct size.
This buffer will always stack-allocate a buffer of size N
(it will simply not be used when a heap allocation is necessary).
|
inline |
Ensure space is available for at least n
elements.
If the current buffer is not large enough to hold n
elements, then a new buffer will be allocated and the contents moved to it. In this case, any previous pointers returned from this object are invalidated.
If a new buffer is allocated, its size will be exactly n
.