|
PSCF v1.5.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 | add (size_t size) |
| Add size of a newly allocated array in bytes to total. | |
| template<typename Data> | |
| static void | deallocate (Data *&ptr, size_t size) |
| Deallocate a C++ array. | |
| template<typename Data> | |
| static void | sub (size_t size) |
| Subtract size of a newly deleted array in bytes from total. | |
| 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 reallocate() or add() have been called. | |
| static long int | nDeallocate () |
| Return number of times deallocate() or sub() have been 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 | clearCounters () |
| Reset total and max counters to zero. | |
| 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.
This function calls C++ new operator to allocate an array containing size elemnents of type Data. It assigns parameter ptr to the address of the first element, adds size * sizeof(Data) to the to the current total, and updates the max counter if the resulting total exceeds the previous maximum.
| ptr | reference to pointer (output) |
| size | number of elements |
Definition at line 172 of file Memory.h.
References add(), UTIL_CHECK, and UTIL_THROW.
Referenced by Pscf::HostRecvArray< Data, CUT >::allocate(), 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 |
Add size of a newly allocated array in bytes to total.
This function accounts for the size of an array that was allocated externally. It adds size * sizeof(Data) to the current counter and updates max if the resulting total exceeds the previous maximum.
| size | number of elements |
Definition at line 191 of file Memory.h.
Referenced by Pscf::FftwDRArray< Data >::allocate(), and allocate().
|
static |
Deallocate a C++ array.
Uses the C++ delete [] operator to deallocate a Data array of size elements of type Data 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 deleted, ptr is set to nullptr, and the total counter is decremented by size * sizeof(Data).
| ptr | reference to pointer (ptr is set to nullptr on output) |
| size | number of elements in existing array |
Definition at line 202 of file Memory.h.
References sub(), and UTIL_CHECK.
Referenced by Util::GArray< Data >::append(), Util::GPArray< Data >::append(), Pscf::HostRecvArray< Data, CUT >::deallocate(), 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(), Pscf::HostRecvArray< Data, CUT >::~HostRecvArray(), Util::ListArray< Data >::~ListArray(), Util::MemoryIArchive::~MemoryIArchive(), Util::MemoryOArchive::~MemoryOArchive(), and Util::RingBuffer< Data >::~RingBuffer().
|
static |
Subtract size of a newly deleted array in bytes from total.
This function accounts for the size of an array that was deleted externally. It subtracts size * sizeof(Data) from the current counter, or throws an Exception if the resulting total would be negative.
| size | number of elements |
Definition at line 217 of file Memory.h.
References UTIL_CHECK.
Referenced by Pscf::FftwDRArray< Data >::deallocate(), deallocate(), and Pscf::FftwDRArray< Data >::~FftwDRArray().
|
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 then 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 230 of file Memory.h.
References allocate(), deallocate(), and UTIL_CHECK.
Referenced by Util::DArray< Data >::reallocate().
|
static |
Return number of times reallocate() or add() have been 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() or sub() have been 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.
|
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.
|
static |
Reset total and max counters to zero.
Definition at line 72 of file Memory.cpp.
|
static |
Call this just to guarantee initialization of static memory.
Definition at line 28 of file Memory.cpp.
Referenced by Util::initStatic().