PSCF v1.4.0
Util::Memory Class Reference

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.

Detailed Description

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.

Definition at line 28 of file Memory.h.

Member Function Documentation

◆ allocate()

◆ deallocate()

template<typename Data>
void Util::Memory::deallocate ( Data *& ptr,
size_t size )
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.

Parameters
ptrreference to pointer (ptr is set null on output)
sizenumber 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().

◆ reallocate()

template<typename Data>
void Util::Memory::reallocate ( Data *& ptr,
size_t oldSize,
size_t newSize )
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.

Parameters
ptrreference to pointer (input/output)
oldSizenumber of elements in existing array
newSizenumber 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().

◆ nAllocate()

long int Util::Memory::nAllocate ( )
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.

◆ nDeallocate()

long int Util::Memory::nDeallocate ( )
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.

◆ total()

long int Util::Memory::total ( )
static

Return total amount of memory currently allocated.

Definition at line 46 of file Memory.cpp.

Referenced by main().

◆ max()

long int Util::Memory::max ( )
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().

◆ initStatic()

void Util::Memory::initStatic ( )
static

Call this just to guarantee initialization of static memory.

Definition at line 28 of file Memory.cpp.

Referenced by Util::initStatic().


The documentation for this class was generated from the following files: