STK++ 0.9.13
STK::hidden::MemHandler< Type_, UnknownSize > Struct Template Reference

Specialization for dynamic size arrays. More...

#include <STK_MemAllocator.h>

Public Types

typedef TRange< UnknownSizeAllocatorRange
 

Static Public Member Functions

static Type_ * free (Type_ *p_data, AllocatorRange const &range)
 shift data pointer and delete allocated memory
 
static Type_ * malloc (Type_ *p_data, AllocatorRange const &range)
 p_data should not point on existing data.
 
template<int OtherSize>
static Type_ * realloc (Type_ *p_data, AllocatorRange const &range, TRange< OtherSize > const &I)
 realloc main pointer and copy existing data.
 

Detailed Description

template<class Type_>
struct STK::hidden::MemHandler< Type_, UnknownSize >

Specialization for dynamic size arrays.

Definition at line 90 of file STK_MemAllocator.h.

Member Typedef Documentation

◆ AllocatorRange

template<class Type_ >
typedef TRange<UnknownSize> STK::hidden::MemHandler< Type_, UnknownSize >::AllocatorRange

Definition at line 92 of file STK_MemAllocator.h.

Member Function Documentation

◆ free()

template<class Type_ >
static Type_ * STK::hidden::MemHandler< Type_, UnknownSize >::free ( Type_ *  p_data,
AllocatorRange const range 
)
inlinestatic

shift data pointer and delete allocated memory

Definition at line 94 of file STK_MemAllocator.h.

95 {
96 // if there is elts
97 if (p_data)
98 {
99 p_data+=range.begin();
100 delete [] p_data; // erase
101 p_data = 0;
102 }
103 return p_data;
104 }

References STK::RangeBase< Derived >::begin().

◆ malloc()

template<class Type_ >
static Type_ * STK::hidden::MemHandler< Type_, UnknownSize >::malloc ( Type_ *  p_data,
AllocatorRange const range 
)
inlinestatic

p_data should not point on existing data.

Just set default value.

Definition at line 106 of file STK_MemAllocator.h.

107 {
108 if(range.size()>0)
109 {
110 p_data = new Type_[range.size()];
111 p_data -= range.begin();
112 }
113 else
114 { p_data = 0;}
115 return p_data;
116 }

References STK::RangeBase< Derived >::begin(), and STK::TRange< UnknownSize >::size().

◆ realloc()

template<class Type_ >
template<int OtherSize>
static Type_ * STK::hidden::MemHandler< Type_, UnknownSize >::realloc ( Type_ *  p_data,
AllocatorRange const range,
TRange< OtherSize > const I 
)
inlinestatic

realloc main pointer and copy existing data.

Definition at line 119 of file STK_MemAllocator.h.

120 {
121 Type_* p = 0;
122 p = malloc(p, I);
123 Range r = inf(range, I);
124 for (int i = r.begin(); i<r.end(); ++i) { p[i] = p_data[i];}
125 p_data = free(p_data, range);
126 return p;
127 }
Range inf(TRange< SizeI_ > const &I, TRange< SizeJ_ > const &J)
compute inf(I,J).
Definition STK_Range.h:477
TRange< UnknownSize > Range
Definition STK_Range.h:59
static Type_ * malloc(Type_ *p_data, AllocatorRange const &range)
p_data should not point on existing data.
static Type_ * free(Type_ *p_data, AllocatorRange const &range)
shift data pointer and delete allocated memory

References STK::RangeBase< Derived >::begin(), STK::TRange< UnknownSize >::end(), STK::hidden::MemHandler< Type_, Size_ >::free(), STK::inf(), and STK::hidden::MemHandler< Type_, Size_ >::malloc().


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