Allocators are used to allocate and deallocate memory. The last template argument of vectors and matrices is the allocator. For a vector: Vector<double, Vect_Full, CallocAlloc<double> >
. CallocAlloc
is an allocator based on calloc
. MallocAlloc
is another allocator based on malloc
. The third available allocator is NewAlloc
, based on new
. The fourth allocator is MallocObject
and allows to allocate objects while using malloc/free functions. The last one is NaNAlloc
, based on malloc
and which initializes allocated elements to "not a number". If a vector or a matrix managed by NaNAlloc
is not properly filled, there will still be NaNs in the vector or the matrix, which is easy to detect.
The default allocator is MallocAlloc
for basic types (bool, float, double, int, complex<double>, etc), NewAlloc otherwise. The default allocator may be changed thanks to SELDON_DEFAULT_ALLOCATOR
:
#define SELDON_DEFAULT_ALLOCATOR NewAlloc
defines NewAlloc
as the default allocator. This line is present in the file SeldonFlag.hxx (which is included if you include SeldonLib.hxx
). If you are including the file Seldon.hxx, this line must be put before #include "Seldon.hxx"
. The file DefaultAllocator contains a list of default allocators for each given type (this is how we enforce MallocAlloc for basic types).
// if you are including SeldonLib.hxx, NewAlloc is already the default allocator for non-basic types #define SELDON_DEFAULT_ALLOCATOR NewAlloc #include "Seldon.hxx" using namespace Seldon; // For vector containing integers, MallocAlloc is okay Vector<int, Vect_Full, MallocAlloc<int> > X; // For vector containing vectors, NewAlloc or MallocObject is needed Vector<Vector<double> > Xvec;