STK++ 0.9.13
|
template base class for all Allocator classes. More...
#include <STK_MemAllocator.h>
Public Types | |
enum | { isNumeric_ = hidden::IsArithmetic<Type_>::yes } |
typedef hidden::MemHandler< Type_, Size_ > | MemHandler |
typedef hidden::MemChooser< isNumeric_, Type_ > | MemChooser |
typedef Type_ | Type |
typedef hidden::RemoveConst< Type >::Type const & | TypeConst |
typedef TRange< Size_ > | AllocatorRange |
Public Member Functions | |
MemAllocator () | |
Default constructor. | |
MemAllocator (AllocatorRange const &I) | |
constructor with specified Range | |
MemAllocator (AllocatorRange const &I, Type const &value) | |
constructor with specified Range and initial value | |
MemAllocator (MemAllocator const &T, bool ref=false) | |
Copy constructor. | |
template<int OtherSize_> | |
MemAllocator (MemAllocator< Type, OtherSize_ > const &T, bool ref=false) | |
Copy constructor. | |
template<int OtherSize_> | |
MemAllocator (MemAllocator< Type, OtherSize_ > const &T, AllocatorRange const &I, bool ref=true) | |
Copy constructor. | |
MemAllocator (Type *const &q, Range const &I, bool ref) | |
Wrapper or copy constructor. | |
MemAllocator (Type *const &q, int size, bool ref) | |
Wrapper or copy constructor: second form. | |
~MemAllocator () | |
destructor. | |
AllocatorRange const & | range () const |
int | begin () const |
int | end () const |
int | size () const |
Type *const & | p_data () const |
Get constant pointer on data. | |
void | setValue (TypeConst value) |
This method allows to set a value to the allocator. | |
void | setValue (int pos, TypeConst value) |
This method allows to set a value to the position pos . | |
TypeConst | elt (int pos) const |
Get the const element number pos. | |
TypeConst | operator[] (int i) const |
Type & | elt (int pos) |
Get the element number pos. | |
Type & | operator[] (int i) |
void | swap (int pos1, int pos2) |
swap two elements of the Allocator. | |
template<int OtherSize> | |
void | malloc (TRange< OtherSize > const &I) |
main method for memory allocation. | |
template<int OtherSize> | |
void | realloc (TRange< OtherSize > const &I) |
function for main ptr memory reallocation. | |
void | free () |
function for main ptr memory deallocation. | |
template<int OtherSize_, int RangeSize_> | |
void | memcpy (int pos, MemAllocator< Type, OtherSize_ > const &T, TRange< RangeSize_ > const &range) |
function copying a part of allocator T in this. | |
template<int RangeSize_> | |
void | memmove (int pos, TRange< RangeSize_ > const &range) |
function moving a part of the allocator. | |
void | memmove (int pos, int begin, int size) |
function moving a part of the allocator. | |
void | exchange (MemAllocator &T) |
exchange this with T. | |
MemAllocator & | assign (MemAllocator const &T) |
copy the Allocator T by value. | |
template<int OtherSize_> | |
MemAllocator & | assign (TRange< OtherSize_ > const &I, Type const &value) |
assign a value to allocator. | |
MemAllocator & | move (MemAllocator const &T) |
move the Allocator T to this. | |
MemAllocator & | shift (int first) |
shift the first index of the data to first. | |
void | setPtr (Type *p_data, Range const &range, bool ref) |
Set address and range of allocated data. | |
template<int OtherSize_> | |
MemAllocator< Type, Size_ > & | assign (TRange< OtherSize_ > const &I, Type const &value) |
bool | isRef () const |
void | setRef (bool ref) const |
Modify the container : can become a reference or the owner of the data. | |
![]() | |
bool | isRef () const |
bool | ref () const |
void | exchange (TRef const &T) |
swap this with the container T. | |
void | setRef (bool ref) const |
Modify the container : can become a reference or the owner of the data. | |
Protected Attributes | |
Type * | p_data_ |
Main pointer on the data. | |
Private Member Functions | |
void | shiftPtr (int inc) |
move main pointer on data | |
void | forcedFree () |
function for main ptr memory deallocation. | |
Private Attributes | |
AllocatorRange | range_ |
Range of the data. | |
Additional Inherited Members | |
![]() | |
TRef (bool ref) | |
Default constructor We have to specify the member ref_. | |
~TRef () | |
destructor. | |
template base class for all Allocator classes.
The MemAllocator class is the base class of all memory allocators. This class manages the main pointer on the data. It derives from the IContainerRef class as an array stored in memory can always be wrapped in some way or be a wrapper of some data stored in memory.
Type_ | can be any type of data that can be stored in memory. |
Size_ | size of the data if it is known at compile time |
Definition at line 180 of file STK_MemAllocator.h.
typedef TRange<Size_> STK::MemAllocator< Type_, Size_ >::AllocatorRange |
Definition at line 189 of file STK_MemAllocator.h.
typedef hidden::MemChooser<isNumeric_, Type_> STK::MemAllocator< Type_, Size_ >::MemChooser |
Definition at line 184 of file STK_MemAllocator.h.
typedef hidden::MemHandler<Type_, Size_> STK::MemAllocator< Type_, Size_ >::MemHandler |
Definition at line 183 of file STK_MemAllocator.h.
typedef Type_ STK::MemAllocator< Type_, Size_ >::Type |
Definition at line 186 of file STK_MemAllocator.h.
typedef hidden::RemoveConst<Type>::Type const& STK::MemAllocator< Type_, Size_ >::TypeConst |
Definition at line 187 of file STK_MemAllocator.h.
Default constructor.
Definition at line 412 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::malloc(), and STK::MemAllocator< Type_, Size_ >::range_.
STK::MemAllocator< Type, Size_ >::MemAllocator | ( | AllocatorRange const & | I | ) |
constructor with specified Range
I | range of the data |
Definition at line 420 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::malloc().
STK::MemAllocator< Type, Size_ >::MemAllocator | ( | AllocatorRange const & | I, |
Type const & | value | ||
) |
constructor with specified Range and initial value
I,value | range and value of the data |
Definition at line 428 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::assign(), and STK::MemAllocator< Type_, Size_ >::malloc().
STK::MemAllocator< Type, Size_ >::MemAllocator | ( | MemAllocator< Type_, Size_ > const & | T, |
bool | ref = false |
||
) |
Copy constructor.
T | the array to copy or reference |
ref | is this a wrapper of T ? (false by default) |
Definition at line 441 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::malloc(), STK::MemAllocator< Type_, Size_ >::memcpy(), STK::MemAllocator< Type_, Size_ >::range(), and STK::TRef<-1 >::ref().
STK::MemAllocator< Type, Size_ >::MemAllocator | ( | MemAllocator< Type, OtherSize_ > const & | T, |
bool | ref = false |
||
) |
Copy constructor.
Copy data or create a reference.
T | the array to copy or reference |
ref | is this a wrapper of T ? (false by default) |
Definition at line 461 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::malloc(), STK::MemAllocator< Type_, Size_ >::memcpy(), STK::MemAllocator< Type_, Size_ >::range(), and STK::TRef<-1 >::ref().
STK::MemAllocator< Type, Size_ >::MemAllocator | ( | MemAllocator< Type, OtherSize_ > const & | T, |
AllocatorRange const & | I, | ||
bool | ref = true |
||
) |
Copy constructor.
Map a range of T.
T,I | the allocator and range to reference |
ref | is this a wrapper of a part of T ? (true by default) |
Definition at line 477 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::malloc(), STK::MemAllocator< Type_, Size_ >::p_data_, and STK::TRef<-1 >::ref().
Wrapper or copy constructor.
q,I | ptr and range of the data to wrap |
ref | is this a wrapper ? If true data will not be freed when this object is released |
Definition at line 496 of file STK_MemAllocator.h.
Wrapper or copy constructor: second form.
This constructor assumes the data as a C-like array. Thus first index is 0.
q,size | ptr and size of the data to wrap |
ref | is this a wrapper ? If true data will not be freed when this object is released |
Definition at line 507 of file STK_MemAllocator.h.
STK::MemAllocator< Type, Size_ >::~MemAllocator | ( | ) |
destructor.
Release memory.
Definition at line 513 of file STK_MemAllocator.h.
MemAllocator< Type, Size_ > & STK::MemAllocator< Type, Size_ >::assign | ( | MemAllocator< Type_, Size_ > const & | T | ) |
copy the Allocator T by value.
The memory is free and the Allocator T is physically copied in this.
T | the allocator to copy by value |
Definition at line 532 of file STK_MemAllocator.h.
Referenced by STK::MemAllocator< Type_, Size_ >::MemAllocator().
MemAllocator & STK::MemAllocator< Type_, Size_ >::assign | ( | TRange< OtherSize_ > const & | I, |
Type const & | value | ||
) |
assign a value to allocator.
I,value | range and value to assign |
MemAllocator< Type, Size_ > & STK::MemAllocator< Type_, Size_ >::assign | ( | TRange< OtherSize_ > const & | I, |
Type const & | value | ||
) |
Definition at line 543 of file STK_MemAllocator.h.
|
inline |
Definition at line 239 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::range_.
Referenced by STK::MemAllocator< Type_, Size_ >::elt(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), STK::MemAllocator< Type_, Size_ >::memmove(), STK::MemAllocator< Type_, Size_ >::memmove(), STK::MemAllocator< Type_, Size_ >::setValue(), STK::MemAllocator< Type_, Size_ >::setValue(), and STK::MemAllocator< Type_, Size_ >::swap().
|
inline |
Get the element number pos.
pos | the position of the element we get |
Definition at line 290 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::p_data_.
|
inline |
Get the const element number pos.
pos | the position of the element we get |
Definition at line 273 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::elt(), STK::MemAllocator< Type_, Size_ >::end(), STK::MemAllocator< Type_, Size_ >::p_data_, and STKOUT_OF_RANGE_1ARG.
Referenced by STK::MemAllocator< Type_, Size_ >::elt(), STK::Array2DNumber< Type_ >::elt0Impl(), STK::Array2DNumber< Type_ >::elt0Impl(), STK::IArray2D< Derived >::elt2Impl(), STK::IArray2D< Derived >::merge(), STK::MemAllocator< Type_, Size_ >::operator[](), STK::MemAllocator< Type_, Size_ >::operator[](), STK::IArray2D< Derived >::ptr(), STK::MemAllocator< Type_, Size_ >::setValue(), STK::IArray2D< Derived >::setValueImpl(), STK::IArray2D< Derived >::transferCol(), and STK::IArray2D< Derived >::transferCol().
|
inline |
Definition at line 241 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::range_.
Referenced by STK::MemAllocator< Type_, Size_ >::elt(), STK::MemAllocator< Type_, Size_ >::memmove(), STK::MemAllocator< Type_, Size_ >::memmove(), STK::MemAllocator< Type_, Size_ >::setValue(), STK::MemAllocator< Type_, Size_ >::setValue(), and STK::MemAllocator< Type_, Size_ >::swap().
void STK::MemAllocator< Type, Size_ >::exchange | ( | MemAllocator< Type_, Size_ > & | T | ) |
exchange this with T.
T | the container to exchange with T |
Definition at line 520 of file STK_MemAllocator.h.
References STK::TRef<-1 >::exchange().
|
inlineprivate |
function for main ptr memory deallocation.
Force memory deallocation, even for fixed size allocators.
Definition at line 403 of file STK_MemAllocator.h.
References STK::hidden::MemHandler< Type_, Size_ >::free(), STK::MemAllocator< Type_, Size_ >::isRef(), STK::MemAllocator< Type_, Size_ >::p_data_, and STK::MemAllocator< Type_, Size_ >::range_.
function for main ptr memory deallocation.
Definition at line 626 of file STK_MemAllocator.h.
true
if *this is reference container, false
otherwise Definition at line 81 of file STK_IContainerRef.h.
Referenced by STK::MemAllocator< Type_, Size_ >::forcedFree(), and STK::IArray2D< Derived >::isRef().
void STK::MemAllocator< Type, Size_ >::malloc | ( | TRange< OtherSize > const & | I | ) |
main method for memory allocation.
I | range of the data allocated |
Definition at line 581 of file STK_MemAllocator.h.
References STK::IRunnerBase::error(), STK::MemAllocator< Type_, Size_ >::malloc(), and STKRUNTIME_ERROR_1ARG.
Referenced by STK::MemAllocator< Type_, Size_ >::malloc(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), and STK::MemAllocator< Type_, Size_ >::MemAllocator().
void STK::MemAllocator< Type, Size_ >::memcpy | ( | int | pos, |
MemAllocator< Type, OtherSize_ > const & | T, | ||
TRange< RangeSize_ > const & | range | ||
) |
function copying a part of allocator T in this.
pos | position where will be copied data |
T,range | the array of data and the range of the data to copy |
Definition at line 637 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::memcpy(), and STKOUT_OF_RANGE_1ARG.
Referenced by STK::MemAllocator< Type_, Size_ >::MemAllocator(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), and STK::MemAllocator< Type_, Size_ >::memcpy().
function moving a part of the allocator.
pos,begin,size | range in form [begin,begin+size) to move at position pos |
Definition at line 650 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::end(), STK::MemAllocator< Type_, Size_ >::memmove(), STKOUT_OF_RANGE_1ARG, and STKOUT_OF_RANGE_2ARG.
void STK::MemAllocator< Type, Size_ >::memmove | ( | int | pos, |
TRange< RangeSize_ > const & | range | ||
) |
function moving a part of the allocator.
pos,range | range in form [begin,end) to move at position pos |
Definition at line 666 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::end(), STK::MemAllocator< Type_, Size_ >::memmove(), and STKOUT_OF_RANGE_1ARG.
Referenced by STK::MemAllocator< Type_, Size_ >::memmove(), and STK::MemAllocator< Type_, Size_ >::memmove().
MemAllocator< Type, Size_ > & STK::MemAllocator< Type, Size_ >::move | ( | MemAllocator< Type_, Size_ > const & | T | ) |
move the Allocator T to this.
The memory of this is freed and T becomes a reference of this. This method allow to move the data of T to this without using physical copy.
T | the allocator to move to this |
Definition at line 558 of file STK_MemAllocator.h.
|
inline |
i | index of the element to get |
Definition at line 294 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::elt().
|
inline |
i | index of the element to get |
Definition at line 286 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::elt().
|
inline |
Get constant pointer on data.
Definition at line 246 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::p_data_.
Referenced by STK::IArray2D< Derived >::merge(), and STK::MemAllocator< Type_, Size_ >::setPtr().
|
inline |
Definition at line 237 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::range_.
Referenced by STK::MemAllocator< Type_, Size_ >::MemAllocator(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), and STK::MemAllocator< Type_, Size_ >::setPtr().
void STK::MemAllocator< Type, Size_ >::realloc | ( | TRange< OtherSize > const & | I | ) |
function for main ptr memory reallocation.
If the size requested is greater than the allocated size, the Type stored are saved and copied using the operator=. the Type class have to provide this operator.
If the size requested is lesser than the allocated size, only the first elements fitting in the container are copied.
I | range of the data to reserve |
Definition at line 603 of file STK_MemAllocator.h.
References STK::RangeBase< Derived >::begin(), STK::IRunnerBase::error(), STK::inf(), STK::MemAllocator< Type_, Size_ >::realloc(), STK::TRange< UnknownSize >::size(), and STKRUNTIME_ERROR_1ARG.
Referenced by STK::MemAllocator< Type_, Size_ >::realloc().
|
inline |
Set address and range of allocated data.
This method is to be used when the memory have been allocated outside. If allocator wrap allocated memory, it is not freed.
p_data | the address to set |
range | range of the data |
ref | is p_data_ a wrapper ? |
Definition at line 382 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::p_data(), STK::MemAllocator< Type_, Size_ >::p_data_, STK::MemAllocator< Type_, Size_ >::range(), STK::MemAllocator< Type_, Size_ >::range_, STK::TRef<-1 >::ref(), and STK::MemAllocator< Type_, Size_ >::setRef().
Modify the container : can become a reference or the owner of the data.
To use with care if we want to avoid memory leak.
ref | : false if this own its own data. |
Definition at line 92 of file STK_IContainerRef.h.
Referenced by STK::MemAllocator< Type_, Size_ >::setPtr().
|
inline |
This method allows to set a value to the position pos
.
pos,value | index and value to set |
Definition at line 259 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::elt(), STK::MemAllocator< Type_, Size_ >::end(), STK::MemAllocator< Type_, Size_ >::p_data_, and STKOUT_OF_RANGE_1ARG.
|
inline |
This method allows to set a value to the allocator.
value | value to set |
Definition at line 251 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::end(), and STK::MemAllocator< Type_, Size_ >::p_data_.
MemAllocator< Type, Size_ > & STK::MemAllocator< Type, Size_ >::shift | ( | int | first | ) |
shift the first index of the data to first.
first | the index of the first data to set |
Definition at line 567 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::shift(), and STKRUNTIME_ERROR_1ARG.
Referenced by STK::MemAllocator< Type_, Size_ >::shift().
|
inlineprivate |
move main pointer on data
inc | the increment to apply |
Definition at line 395 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::p_data_, and STK::MemAllocator< Type_, Size_ >::range_.
|
inline |
Definition at line 243 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::range_.
Referenced by STK::IArray2D< Derived >::availableCols().
|
inline |
swap two elements of the Allocator.
pos1,pos2 | the positions to swap |
Definition at line 298 of file STK_MemAllocator.h.
References STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::end(), STK::MemAllocator< Type_, Size_ >::p_data_, STKOUT_OF_RANGE_2ARG, and STK::MemAllocator< Type_, Size_ >::swap().
Referenced by STK::MemAllocator< Type_, Size_ >::swap(), and STK::IArray2D< Derived >::swapCols().
|
protected |
Main pointer on the data.
Definition at line 387 of file STK_MemAllocator.h.
Referenced by STK::MemAllocator< Type_, Size_ >::elt(), STK::MemAllocator< Type_, Size_ >::elt(), STK::MemAllocator< Type_, Size_ >::forcedFree(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), STK::MemAllocator< Type_, Size_ >::p_data(), STK::MemAllocator< Type_, Size_ >::setPtr(), STK::MemAllocator< Type_, Size_ >::setValue(), STK::MemAllocator< Type_, Size_ >::setValue(), STK::MemAllocator< Type_, Size_ >::shiftPtr(), and STK::MemAllocator< Type_, Size_ >::swap().
|
private |
Range of the data.
Definition at line 391 of file STK_MemAllocator.h.
Referenced by STK::MemAllocator< Type_, Size_ >::begin(), STK::MemAllocator< Type_, Size_ >::end(), STK::MemAllocator< Type_, Size_ >::forcedFree(), STK::MemAllocator< Type_, Size_ >::MemAllocator(), STK::MemAllocator< Type_, Size_ >::range(), STK::MemAllocator< Type_, Size_ >::setPtr(), STK::MemAllocator< Type_, Size_ >::shiftPtr(), and STK::MemAllocator< Type_, Size_ >::size().