|
PSCF v1.4.0
|
Provides method to allocate array. More...
#include <Memory.h>
Static Public Member Functions | |
| template<typename Data> | |
| static void | allocate (Data *&ptr, size_t size) |
| Allocate a C++ array. | |
| template<typename Data> | |
| static void | deallocate (Data *&ptr, size_t size) |
| Deallocate a C++ array. | |
| template<typename Data> | |
| static void | reallocate (Data *&ptr, size_t oldSize, size_t newSize) |
| Reallocate a C++ array. | |
| static long int | nAllocate () |
| Return number of times allocate() was called. | |
| static long int | nDeallocate () |
| Return number of times deallocate() was called. | |
| static long int | total () |
| Return total amount of memory currently allocated. | |
| static long int | max () |
| Return the maximum amount of allocated heap memory thus far. | |
| static void | initStatic () |
| Call this just to guarantee initialization of static memory. | |
Provides method to allocate array.
The Memory::allocate() method invokes the new operator within a try-catch block, and keeps track of the total memory allocated via this class.
|
static |
Allocate a C++ array.
Uses new to allocates a Data array of size elements, assigns ptr the address of the first element.
| ptr | reference to pointer (output) |
| size | number of elements |
Definition at line 136 of file Memory.h.
References UTIL_CHECK, and UTIL_THROW.
Referenced by Util::ArraySet< Data >::allocate(), Util::ArrayStack< Data >::allocate(), Util::DArray< Data >::allocate(), Util::DMatrix< Data >::allocate(), Util::DPArray< Data >::allocate(), Util::DRaggedMatrix< Data >::allocate(), Util::DRArray< Data >::allocate(), Util::DSArray< Data >::allocate(), Util::GridArray< Data >::allocate(), Util::ListArray< Data >::allocate(), Util::MemoryIArchive::allocate(), Util::MemoryOArchive::allocate(), Util::RingBuffer< Data >::allocate(), Util::GArray< Data >::append(), Util::GPArray< Data >::append(), Util::DArray< Data >::DArray(), Util::DSArray< Data >::DSArray(), Util::GArray< Data >::GArray(), Util::GPArray< Data >::GPArray(), Util::GStack< Data >::GStack(), Util::RingBuffer< Data >::operator=(), Util::GStack< Data >::push(), Util::DArray< Data >::reallocate(), reallocate(), Util::GArray< Data >::reserve(), Util::GPArray< Data >::reserve(), Util::GStack< Data >::reserve(), and Util::GArray< Data >::resize().
|
static |
Deallocate a C++ array.
Uses free to deallocate a Data array of size elements that was allocated by the Memory::allocate member function. On input, ptr must be the pointer to an array of elements of type Data, and size must be the number of elements. On output, the array is deallocated and ptr is set to nullptr.
| ptr | reference to pointer (ptr is set null on output) |
| size | number of elements in existing array |
Definition at line 157 of file Memory.h.
References UTIL_CHECK.
Referenced by Util::GArray< Data >::append(), Util::GPArray< Data >::append(), Util::DArray< Data >::deallocate(), Util::DMatrix< Data >::deallocate(), Util::DRArray< Data >::deallocate(), Util::GArray< Data >::deallocate(), Util::GPArray< Data >::deallocate(), Util::GStack< Data >::deallocate(), Util::GStack< Data >::push(), reallocate(), Util::GArray< Data >::reserve(), Util::GPArray< Data >::reserve(), Util::GStack< Data >::reserve(), Util::GArray< Data >::resize(), Util::ArraySet< Data >::~ArraySet(), Util::ArrayStack< Data >::~ArrayStack(), Util::DArray< Data >::~DArray(), Util::DMatrix< Data >::~DMatrix(), Util::DPArray< Data >::~DPArray(), Util::DRaggedMatrix< Data >::~DRaggedMatrix(), Util::DRArray< Data >::~DRArray(), Util::DSArray< Data >::~DSArray(), Util::GArray< Data >::~GArray(), Util::GPArray< Data >::~GPArray(), Util::GridArray< Data >::~GridArray(), Util::GStack< Data >::~GStack(), Util::ListArray< Data >::~ListArray(), Util::MemoryIArchive::~MemoryIArchive(), Util::MemoryOArchive::~MemoryOArchive(), and Util::RingBuffer< Data >::~RingBuffer().
|
static |
Reallocate a C++ array.
This function calls allocate to allocate a new array of size newSize. If oldSize > 0, it copies all existing elements and deallocates the old array. On return, ptr is the address of the new array.
Precondition: On input, newSize > 0 and newSize > oldSize.
| ptr | reference to pointer (input/output) |
| oldSize | number of elements in existing array |
| newSize | number of elements in new array |
Definition at line 175 of file Memory.h.
References allocate(), deallocate(), and UTIL_CHECK.
Referenced by Util::DArray< Data >::reallocate().
|
static |
Return number of times allocate() was called.
Each call to reallocate() also increments nAllocate(), because allocate() is called internally.
Definition at line 34 of file Memory.cpp.
|
static |
Return number of times deallocate() was called.
Each call to reallocate() also increments nDeallocate(), because deallocate() is called internally.
Definition at line 40 of file Memory.cpp.
|
static |
Return total amount of memory currently allocated.
Definition at line 46 of file Memory.cpp.
Referenced by main().
|
static |
Return the maximum amount of allocated heap memory thus far.
This function returns the temporal maximum of total().
Definition at line 52 of file Memory.cpp.
Referenced by main().
|
static |
Call this just to guarantee initialization of static memory.
Definition at line 28 of file Memory.cpp.
Referenced by Util::initStatic().