1 #ifndef NPSTAT_ALLOCATORS_HH_
2 #define NPSTAT_ALLOCATORS_HH_
24 #pragma GCC diagnostic push
25 #pragma GCC diagnostic ignored "-Wfree-nonheap-object"
27 void reallyDestroyBuffer(T* thisBuffer) {
delete [] thisBuffer;}
28 #pragma GCC diagnostic pop
31 void dontDestroyBuffer(T* ) {}
39 inline T*
makeBuffer(
unsigned sizeNeeded, T* stackBuffer,
40 unsigned sizeofStackBuffer)
42 if (sizeNeeded > sizeofStackBuffer || stackBuffer == 0)
43 return new T[sizeNeeded];
52 void (*fcn_ptr)(T*) = thisBuffer == stackBuffer ?
53 &Private::dontDestroyBuffer<T> : &Private::reallyDestroyBuffer<T>;
58 template <
typename T1,
typename T2>
59 inline void copyBuffer(T1* dest,
const T2* source,
const unsigned long len)
65 for (
unsigned long i=0; i<len; ++i)
66 *dest++ =
static_cast<T1
>(*source++);
74 template <
typename T1,
typename T2>
76 const unsigned long dim)
82 for (
unsigned long i=0; i<dim; ++i)
84 for (
unsigned long j=0; j<dim; ++j)
85 dest[j*dim] =
static_cast<T1
>(*source++);
95 template <
typename T1,
typename T2>
97 const unsigned long M,
98 const unsigned long N)
104 for (
unsigned long i=0; i<M; ++i)
106 for (
unsigned long j=0; j<N; ++j)
107 dest[j*M] =
static_cast<T1
>(*source++);
117 template <
typename T>
124 for (
unsigned long i=0; i<len; ++i)
Definition: AbsArrayProjector.hh:14
void clearBuffer(T *buf, const unsigned long len)
Definition: allocators.hh:118
void destroyBuffer(T *thisBuffer, const T *stackBuffer)
Definition: allocators.hh:50
void transposeBuffer(T1 *dest, const T2 *source, const unsigned long dim)
Definition: allocators.hh:75
void copyBuffer(T1 *dest, const T2 *source, const unsigned long len)
Definition: allocators.hh:59
T * makeBuffer(unsigned sizeNeeded, T *stackBuffer, unsigned sizeofStackBuffer)
Definition: allocators.hh:39