geomc 1.0
A c++ linear algebra template library
Public Member Functions | List of all members
SmallStorage< T, N > Class Template Reference

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 ith element in the array.
 
operator[] (index_t i) const
 Return the ith element in the array.
 
void resize (index_t n)
 Ensure space is available for at least n elements. More...
 

Detailed Description

template<typename T, index_t N>
class geom::SmallStorage< T, N >

Array storage which does not allocate from the heap unless the requested size is larger than a threshhold, N.

Template Parameters
TElement type.
NMaximum 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).

Member Function Documentation

◆ resize()

void resize ( index_t  n)
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.


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