32 #ifndef SACADO_FAD_MEMPOOLSTORAGE_HPP
33 #define SACADO_FAD_MEMPOOLSTORAGE_HPP
37 #ifdef SACADO_NEW_FAD_DESIGN_IS_DEFAULT
45 using MemPoolStorage = Exp::MemPoolStorage<T>;
65 template <typename T, bool isScalar = IsScalarType<T>::value>
71 T* m =
static_cast<T*
>(pool->alloc());
73 for (
int i=0; i<sz; ++i)
84 T* m =
static_cast<T*
>(pool->
alloc());
86 for (
int i=0; i<sz; ++i)
100 T* m =
static_cast<T*
>(pool->
alloc());
102 for (
int i=0; i<sz; ++i)
103 new (p++)
T(*(src++));
111 static inline void copy(
const T* src,
T* dest,
int sz) {
112 for (
int i=0; i<sz; ++i)
113 *(dest++) = *(src++);
117 static inline void zero(
T* dest,
int sz) {
118 for (
int i=0; i<sz; ++i)
125 for (
T* b = m; b!=e; b++)
127 pool->
free((
void*) m);
135 template <
typename T>
141 T* m =
static_cast<T*
>(pool->alloc());
151 T* m =
static_cast<T*
>(pool->
alloc());
152 std::memset(m,0,sz*
sizeof(
T));
165 T* m =
static_cast<T*
>(pool->
alloc());
167 for (
int i=0; i<sz; ++i)
168 new (p++)
T(*(src++));
176 static inline void copy(
const T* src,
T* dest,
int sz) {
177 std::memcpy(dest,src,sz*
sizeof(
T));
181 static inline void zero(
T* dest,
int sz) {
183 std::memset(dest,0,sz*
sizeof(
T));
188 pool->
free((
void*) m);
193 template <
typename T>
201 template <
typename S>
359 #endif // SACADO_NEW_FAD_DESIGN_IS_DEFAULT
361 #endif // SACADO_FAD_MEMPOOLSTORAGE_HPP
static void destroy_and_release(T *m, int sz, MemPool *pool)
Destroy array elements and release memory.
#define SACADO_ENABLE_VALUE_CTOR_DECL
Sacado::Fad::MemPool * defaultPool_
void resizeAndZero(int sz)
Resize the derivative array to sz.
static T * get_and_fill(int sz, MemPool *pool)
Get memory for new array of length sz and fill with zeros.
static T * get_and_fill(const T *src, int sz, MemPool *pool)
Get memory for new array of length sz and fill with entries from src.
void resize(int sz)
Resize the derivative array to sz.
void free(void *b)
Free an element.
static MemPool * defaultPool_
Default memory pool.
T & fastAccessDx(int i)
Returns derivative component i without bounds checking.
static T * get_and_fill(int sz, MemPool *pool)
Get memory for new array of length sz and fill with zeros.
const T & val() const
Returns value.
MemPoolStorage(const S &x, SACADO_ENABLE_VALUE_CTOR_DECL)
Default constructor.
MemPoolStorage & operator=(const MemPoolStorage &x)
Assignment.
Dynamic array allocation class that works for any type.
static T * get(int sz, MemPool *pool)
Get memory for new array of length sz.
static void copy(const T *src, T *dest, int sz)
Copy array from src to dest of length sz.
static void copy(const T *src, T *dest, int sz)
Copy array from src to dest of length sz.
int sz_
Derivative array size.
Derivative array storage class using dynamic memory allocation.
void zero()
Zero out derivative array.
MemPoolStorage(const int sz, const T &x, const DerivInit zero_out=InitDerivArray)
Constructor with size sz.
static T * get_and_fill(const T *src, int sz, MemPool *pool)
Get memory for new array of length sz and fill with entries from src.
static void destroy_and_release(T *m, int sz, MemPool *pool)
Destroy array elements and release memory.
DerivInit
Enum use to signal whether the derivative array should be initialized in AD object constructors...
const T * dx() const
Returns derivative array.
int len_
Derivative array length.
~MemPoolStorage()
Destructor.
MemPool * myPool_
Memory pool.
const T & fastAccessDx(int i) const
Returns derivative component i without bounds checking.
void * alloc()
Allocate a new element.
Initialize the derivative array.
static void zero(T *dest, int sz)
Zero out array dest of length sz.
void expand(int sz)
Expand derivative array to size sz.
MemPoolStorage(const MemPoolStorage &x)
Copy constructor.
int size() const
Returns number of derivative components.
static void zero(T *dest, int sz)
Zero out array dest of length sz.
T dx(int i) const
Returns derivative component i with bounds checking.