44 template <
typename Data>
45 static void allocate(Data*& ptr,
size_t size);
56 template <
typename Data>
57 static void add(
size_t size);
72 template <
typename Data>
73 static void deallocate(Data*& ptr,
size_t size);
85 template <
typename Data>
86 static void sub(
size_t size);
102 template <
typename Data>
103 static void reallocate(Data*& ptr,
size_t oldSize,
size_t newSize);
124 static long int total();
131 static long int max();
137 static long int max(MPI::Intracomm& communicator);
153 static long int total_;
156 static long int max_;
159 static long int nAllocate_;
162 static long int nDeallocate_;
171 template <
typename Data>
175 UTIL_THROW(
"Attempt to allocate to non-null pointer");
178 ptr =
new Data[size];
180 }
catch (std::bad_alloc&) {
181 std::cout <<
"Allocation error in Util::Memory" << std::endl;
190 template <
typename Data>
193 total_ += size *
sizeof(Data);
195 if (total_ > max_) max_ = total_;
201 template <
typename Data>
216 template <
typename Data>
220 long int change = size *
sizeof(Data);
229 template <
typename Data>
235 Data* newPtr =
nullptr;
239 for (
size_t i = 0; i < oldSize; ++i) {
Provides method to allocate array.
static void sub(size_t size)
Subtract size of a newly deleted array in bytes from total.
static long int nDeallocate()
Return number of times deallocate() or sub() have been called.
static void deallocate(Data *&ptr, size_t size)
Deallocate a C++ array.
static long int nAllocate()
Return number of times reallocate() or add() have been called.
static long int max()
Return the maximum amount of allocated heap memory thus far.
static long int total()
Return total amount of memory currently allocated.
static void reallocate(Data *&ptr, size_t oldSize, size_t newSize)
Reallocate a C++ array.
static void initStatic()
Call this just to guarantee initialization of static memory.
static void clearCounters()
Reset total and max counters to zero.
static void allocate(Data *&ptr, size_t size)
Allocate a C++ array.
static void add(size_t size)
Add size of a newly allocated array in bytes to total.
File containing preprocessor macros for error handling.
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
#define UTIL_THROW(msg)
Macro for throwing an Exception, reporting function, file and line number.
Utility classes for scientific computation.