PSCF v1.1
Static Public Member Functions | List of all members
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. More...
 
template<typename Data >
static void deallocate (Data *&ptr, size_t size)
 Deallocate a C++ array. More...
 
template<typename Data >
static void reallocate (Data *&ptr, size_t oldSize, size_t newSize)
 Reallocate a C++ array. More...
 
static int nAllocate ()
 Return number of times allocate() was called. More...
 
static int nDeallocate ()
 Return number of times deallocate() was called. More...
 
static int total ()
 Return total amount of memory currently allocated. More...
 
static int max ()
 Return the maximum amount of allocated heap memory thus far. More...
 
static int max (MPI::Intracomm &communicator)
 Return max for any processor in communicator. More...
 
static void initStatic ()
 Call this just to guarantee initialization of static memory. More...
 

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.

Definition at line 28 of file Memory.h.

Member Function Documentation

◆ allocate()

template<typename Data >
void Util::Memory::allocate ( Data *&  ptr,
size_t  size 
)
static

Allocate a C++ array.

Uses new to allocates a Data array of size elements, assigns ptr the address of the first element.

Parameters
ptrreference to pointer (output)
sizenumber of elements

Definition at line 132 of file Memory.h.

References UTIL_THROW.

Referenced by Util::DArray< Data >::DArray(), Pscf::Field< T >::Field(), and reallocate().

◆ 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.

Parameters
ptrreference to pointer (intput, ptr = 0 on output)
sizenumber of elements in existing array

Definition at line 152 of file Memory.h.

References UTIL_CHECK.

Referenced by reallocate(), Util::GPArray< Data >::~GPArray(), and Util::GStack< Data >::~GStack().

◆ 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, copies all existing elements and deallocates old and calls deallocate to free the old array. On outputs, ptr is the address of the new array.

Precondition: On input, newSize > oldSize.

Parameters
ptrreference to pointer (input/output)
oldSizenumber of elements in existing array
newSizenumber of elements in new array

Definition at line 168 of file Memory.h.

References allocate(), deallocate(), and UTIL_CHECK.

◆ nAllocate()

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()

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()

int Util::Memory::total ( )
static

Return total amount of memory currently allocated.

Definition at line 46 of file Memory.cpp.

◆ max() [1/2]

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.

◆ max() [2/2]

int Util::Memory::max ( MPI::Intracomm &  communicator)
static

Return max for any processor in communicator.

Definition at line 56 of file Memory.cpp.

◆ 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: