MAIA bb96820c
Multiphysics at AIA
Loading...
Searching...
No Matches
alloc.h File Reference

Go to the source code of this file.

Namespaces

namespace  maia
 Namespace for auxiliary functions/classes.
 
namespace  maia::alloc
 

Functions

void maia::alloc::debug (const MString &objectName, const MString &elementsName)
 Debug output for mAlloc. More...
 
void maia::alloc::debug (const MString &objectName)
 
void maia::alloc::debug_collector (const MString &objectName, const MInt maxSize, const MString &function)
 
void maia::alloc::debug_list (const MString &objectName, const MInt maxSize, const MString &function)
 
template<class T >
MInt maia::alloc::findAllocatedObject (const T *const a, std::vector< GenericObject * >::iterator &hit)
 Find the allocated object for a given pointer. More...
 
template<class T >
MBool maia::alloc::isAllocated (const T *const a)
 Check if the given pointer belongs to an allocated object. More...
 
template<class T >
void maia::alloc::checkPointer (const T *const a, const MString objectName, const MString function)
 
template<class T >
void maia::alloc::checkPointer (const T *const, const MString &, const MString &)
 
template<class T >
void maia::alloc::store_collector (Collector< T > *a, MLong maxSize, const MString &objectName, const MString &functionName)
 
template<class T >
Collector< T > * maia::alloc::make_collector (const MLong size, const MInt dummy1, const MInt dummy2, const MInt dummy3, const MInt dummy4)
 
template<class T >
Collector< T > * maia::alloc::make_collector (const MLong size, const MInt dimension, const MFloat dummy, const MInt maxNoSets)
 
template<class T >
Collector< T > * maia::alloc::make_collector (const MLong size, const MInt dimension, const MInt dummy, const MInt dummy1)
 
template<class T >
Collector< T > * maia::alloc::make_collector (const MLong size, const MInt dimension, const MInt distributions, const MInt distributions1, const MInt maxNoSurfaces, const MInt dummy1)
 
template<class T >
Collector< T > * maia::alloc::make_collector (const MLong size, const MInt dimension, const MInt distributions)
 
template<class T >
Collector< T > * maia::alloc::make_collector (const MLong size, const MInt dimension)
 
template<class T >
Collector< T > * maia::alloc::make_collector (const MLong size)
 
MLong allocatedBytes ()
 Return the number of allocated bytes. More...
 
MLong maxAllocatedBytes ()
 Return the maximum number of allocated bytes. More...
 
template<class T >
void mAlloc (T *&a, const MLong N, const MString &objectName, MString function)
 allocates memory for one-dimensional array 'a' of size N More...
 
template<class T >
void mAlloc (T *&a, const MLong N, const MString &objectName, const T initialValue, MString function)
 allocates memory for one-dimensional array 'a' of size N More...
 
template<class T >
void mAlloc (T **&a, const MLong N, const MLong M, const MString &objectName, const T initialValue, MString function)
 allocates memory for two-dimensional array 'a' of size NxM More...
 
template<class T >
void mAlloc (T **&a, const MLong N, const MLong M, const MString &objectName, MString function)
 allocates memory for two-dimensional array 'a' of size NxM More...
 
template<class T >
void mAlloc (T **&a, const MLong N, const MInt *arraySizes, const MString &objectName, MString function)
 allocates memory for two-dimensional array 'a' of size N x arraySizes[0:N-1] More...
 
template<class T >
void mAlloc (T **&a, const MLong N, const MInt *const arraySizes, MInt factor, const MString &objectName, MString function)
 allocates memory for two-dimensional array 'a' of size N x (factor*arraySizes[0:N-1]) More...
 
template<class T >
void mAlloc (List< T > *&a, const MLong N, const MString &objectName, const T initialValue, MString function)
 allocates memory for List container More...
 
template<class T >
void mAlloc (Collector< T > *&a, MLong maxSize, MInt dummy1, MInt dummy2, MInt dummy3, MInt dummy4, const MString &objectName, MString function)
 allocates memory for Collector More...
 
template<class T >
void mAlloc (Collector< T > *&a, MLong maxSize, MInt dimension, MFloat dummy, MInt maxNoSets, const MString &objectName, MString function)
 allocates memory for Collector More...
 
template<class T >
void mAlloc (Collector< T > *&a, MLong maxSize, MInt dimension, MInt dummy, MInt dummy1, const MString &objectName, MString function)
 allocates memory for Collector More...
 
template<class T >
void mAlloc (Collector< T > *&a, MLong maxSize, MInt dimension, MInt distributions, MInt distributions1, MInt maxNoSurfaces, MInt dummy1, const MString &objectName, MString function)
 Allocates memory for Collector. More...
 
template<class T >
void mAlloc (Collector< T > *&a, MLong maxSize, MInt dimension, MInt distributions, const MString &objectName, MString function)
 allocates memory for Collector More...
 
template<class T >
void mAlloc (Collector< T > *&a, MLong maxSize, MInt dimension, const MString &objectName, MString function)
 allocates memory for Collector More...
 
template<class T >
void mAlloc (Collector< T > *&a, MLong maxSize, const MString &objectName, MString function)
 allocates memory for Collector More...
 
template<class T >
MBool mDeallocate (T *&a)
 deallocates the memory previously allocated for element 'a' More...
 
void mDealloc ()
 Deallocates all memory allocated previously by mAlloc(...) More...
 
void printAllocatedObjects ()
 Prints the name of all objects which are currently allocated via mAlloc. More...
 
void printAllocatedObjects (const MString &filterString)
 Prints the name of all objects which are currently allocated via mAlloc and contain the given string. More...
 

Function Documentation

◆ allocatedBytes()

MLong allocatedBytes ( )

Definition at line 121 of file alloc.cpp.

◆ mAlloc() [1/14]

template<class T >
void mAlloc ( Collector< T > *&  a,
MLong  maxSize,
const MString objectName,
MString  function 
)
Author
Lennart Schneiders
Date
08.12.2011

Definition at line 530 of file alloc.h.

530 {
531 maia::alloc::checkPointer(a, objectName, function);
532 maia::alloc::debug_collector(objectName, maxSize, function);
533 a = maia::alloc::make_collector<T>(maxSize);
534 maia::alloc::store_collector(a, maxSize, objectName, function);
535}
void debug_collector(const MString &objectName, const MInt maxSize, const MString &function)
Definition: alloc.h:42
void store_collector(Collector< T > *a, MLong maxSize, const MString &objectName, const MString &functionName)
Definition: alloc.h:116
void checkPointer(const T *const a, const MString objectName, const MString function)
Definition: alloc.h:99
Definition: contexttypes.h:19

◆ mAlloc() [2/14]

template<class T >
void mAlloc ( Collector< T > *&  a,
MLong  maxSize,
MInt  dimension,
const MString objectName,
MString  function 
)
Author
Lennart Schneiders
Date
08.12.2011

Definition at line 516 of file alloc.h.

516 {
517 maia::alloc::checkPointer(a, objectName, function);
518 maia::alloc::debug_collector(objectName, maxSize, function);
519 a = maia::alloc::make_collector<T>(maxSize, dimension);
520 maia::alloc::store_collector(a, maxSize, objectName, function);
521}

◆ mAlloc() [3/14]

template<class T >
void mAlloc ( Collector< T > *&  a,
MLong  maxSize,
MInt  dimension,
MFloat  dummy,
MInt  maxNoSets,
const MString objectName,
MString  function 
)
Author
Lennart Schneiders
Date
08.12.2011

Definition at line 447 of file alloc.h.

448 {
449 maia::alloc::checkPointer(a, objectName, function);
450 maia::alloc::debug_collector(objectName, maxSize, function);
451 a = maia::alloc::make_collector<T>(maxSize, dimension, dummy, maxNoSets);
452 maia::alloc::store_collector(a, maxSize, objectName, function);
453}

◆ mAlloc() [4/14]

template<class T >
void mAlloc ( Collector< T > *&  a,
MLong  maxSize,
MInt  dimension,
MInt  distributions,
const MString objectName,
MString  function 
)
Author
Lennart Schneiders
Date
08.12.2011

Used to allocate:

  • DG: m_elements

Definition at line 501 of file alloc.h.

502 {
503 maia::alloc::checkPointer(a, objectName, function);
504 maia::alloc::debug_collector(objectName, maxSize, function);
505 a = maia::alloc::make_collector<T>(maxSize, dimension, distributions);
506 maia::alloc::store_collector(a, maxSize, objectName, function);
507}

◆ mAlloc() [5/14]

template<class T >
void mAlloc ( Collector< T > *&  a,
MLong  maxSize,
MInt  dimension,
MInt  distributions,
MInt  distributions1,
MInt  maxNoSurfaces,
MInt  dummy1,
const MString objectName,
MString  function 
)

Used to allocate:

Author
Lennart Schneiders
Date
08.12.2011

Definition at line 483 of file alloc.h.

484 {
485 maia::alloc::checkPointer(a, objectName, function);
486 maia::alloc::debug_collector(objectName, maxSize, function);
487 a = maia::alloc::make_collector<T>(maxSize, dimension, distributions, distributions1, maxNoSurfaces, dummy1);
488 maia::alloc::store_collector(a, maxSize, objectName, function);
489}

◆ mAlloc() [6/14]

template<class T >
void mAlloc ( Collector< T > *&  a,
MLong  maxSize,
MInt  dimension,
MInt  dummy,
MInt  dummy1,
const MString objectName,
MString  function 
)
Author
Lennart Schneiders
Date
08.12.2011

Used to allocate:

  • DG: m_surfaces

Definition at line 465 of file alloc.h.

466 {
467 maia::alloc::checkPointer(a, objectName, function);
468 maia::alloc::debug_collector(objectName, maxSize, function);
469 a = maia::alloc::make_collector<T>(maxSize, dimension, dummy, dummy1);
470 maia::alloc::store_collector(a, maxSize, objectName, function);
471}

◆ mAlloc() [7/14]

template<class T >
void mAlloc ( Collector< T > *&  a,
MLong  maxSize,
MInt  dummy1,
MInt  dummy2,
MInt  dummy3,
MInt  dummy4,
const MString objectName,
MString  function 
)
Author
Lennart Schneiders
Date
08.12.2011

Definition at line 432 of file alloc.h.

433 {
434 maia::alloc::checkPointer(a, objectName, function);
435 maia::alloc::debug_collector(objectName, maxSize, function);
436 a = maia::alloc::make_collector<T>(maxSize, dummy1, dummy2, dummy3, dummy4);
437 maia::alloc::store_collector(a, maxSize, objectName, function);
438}

◆ mAlloc() [8/14]

template<class T >
void mAlloc ( List< T > *&  a,
const MLong  N,
const MString objectName,
const T  initialValue,
MString  function 
)
Author
Lennart Schneiders
Date
08.12.2011

Definition at line 397 of file alloc.h.

397 {
398 using namespace maia::alloc;
399 maia::alloc::debug_list(objectName, N, function);
400 maia::alloc::checkPointer(a, objectName, function);
401
402#ifdef MAIA_ASSERT_ALLOC
403 ASSERT(N > 0, "Error in mAlloc: size must be >0, is " + std::to_string(N) + " for " + objectName + " allocated in "
404 + function);
405#endif
406
407 if(N <= 0) {
408#ifdef MAIA_DEBUG_ALLOC
409 std::cerr << "Warning in mAlloc: size should be >0, is " << std::to_string(N) << " for " << objectName
410 << " allocated in " << function << std::endl;
411#endif
412 return;
413 }
414
415 a = new List<T>(N);
416
417 g_allocatedObjects.push_back(new GenericPointer<List<T>>(a, objectName, N * sizeof(T), function, false));
418
419#ifndef SKIP_INITIAL_VALUE_ALLOC
420 for(MInt i = 0; i < N; i++)
421 a->a[i] = initialValue;
422#endif
423}
class containing a generic pointer
Definition: genericobject.h:60
Definition: list.h:16
int32_t MInt
Definition: maiatypes.h:62
std::vector< GenericObject * > g_allocatedObjects
void debug_list(const MString &objectName, const MInt maxSize, const MString &function)
Definition: alloc.h:48

◆ mAlloc() [9/14]

template<class T >
void mAlloc ( T *&  a,
const MLong  N,
const MString objectName,
const T  initialValue,
MString  function 
)
Author
Lennart Schneiders
Date
08.12.2011

Definition at line 201 of file alloc.h.

201 {
202 mAlloc(a, N, objectName, function);
203#ifndef SKIP_INITIAL_VALUE_ALLOC
204 for(MInt i = 0; i < N; i++)
205 a[i] = initialValue;
206#endif
207}
void mAlloc(T *&a, const MLong N, const MString &objectName, MString function)
allocates memory for one-dimensional array 'a' of size N
Definition: alloc.h:173

◆ mAlloc() [10/14]

template<class T >
void mAlloc ( T *&  a,
const MLong  N,
const MString objectName,
MString  function 
)
Author
Lennart Schneiders
Date
08.12.2011

Definition at line 173 of file alloc.h.

173 {
174 using namespace maia::alloc;
175 maia::alloc::debug(objectName);
176 maia::alloc::checkPointer(a, objectName, function);
177
178#ifdef MAIA_ASSERT_ALLOC
179 ASSERT(N > 0, "Error in mAlloc: size must be >0, is " + std::to_string(N) + " for " + objectName + " allocated in "
180 + function);
181#endif
182
183 if(N <= 0) {
184#ifdef MAIA_DEBUG_ALLOC
185 std::cerr << "Warning in mAlloc: size should be >0, is " << std::to_string(N) << " for " << objectName
186 << " allocated in " << function << std::endl;
187#endif
188 return;
189 }
190
191 a = new T[N];
192 g_allocatedObjects.push_back(new GenericPointer<T>(a, objectName, N * sizeof(T), function, true));
193}
void debug(const MString &objectName, const MString &elementsName)
Debug output for mAlloc.
Definition: alloc.h:31

◆ mAlloc() [11/14]

template<class T >
void mAlloc ( T **&  a,
const MLong  N,
const MInt arraySizes,
const MString objectName,
MString  function 
)
Author
Lennart Schneiders
Date
08.12.2011

Definition at line 301 of file alloc.h.

301 {
302 using namespace maia::alloc;
303 maia::alloc::debug(objectName);
304 maia::alloc::checkPointer(a, objectName, function);
305
306 size_t size = 0;
307 for(MInt k = 0; k < N; k++) {
308 size += arraySizes[k];
309 }
310
311#ifdef MAIA_ASSERT_ALLOC
312 ASSERT(N > 0 && size > 0, "Error in mAlloc: sizes must be >0, but they are " + std::to_string(N) + " and "
313 + std::to_string(size) + " for " + objectName + " allocated in " + function);
314#endif
315
316 if(N <= 0 || size <= 0) {
317#ifdef MAIA_DEBUG_ALLOC
318 std::cerr << "Error in mAlloc: sizes should be >0, but they are " << std::to_string(N) << " and "
319 << std::to_string(size) << " for " << objectName << " allocated in " << function << std::endl;
320#endif
321 return;
322 }
323
324 a = new T*[N];
325 g_allocatedObjects.push_back(new GenericPointer<T*>(a, objectName, N * sizeof(T*), function, true));
326
327 const MString elementsName = "_elements";
328 maia::alloc::debug(objectName, elementsName);
329
330 T* dummy = new T[size];
331 g_allocatedObjects.push_back(
332 new GenericPointer<T>(dummy, objectName + elementsName, size * sizeof(T), function, true, false));
333
334 size_t cnt = 0;
335 for(MInt i = 0; i < N; i++) {
336 a[i] = (T*)(&(dummy[cnt]));
337 cnt += arraySizes[i];
338 }
339}
std::basic_string< char > MString
Definition: maiatypes.h:55

◆ mAlloc() [12/14]

template<class T >
void mAlloc ( T **&  a,
const MLong  N,
const MInt *const  arraySizes,
MInt  factor,
const MString objectName,
MString  function 
)
Author
Lennart Schneiders
Date
08.12.2011

Definition at line 349 of file alloc.h.

350 {
351 using namespace maia::alloc;
352 maia::alloc::debug(objectName);
353 maia::alloc::checkPointer(a, objectName, function);
354
355 size_t size = 0;
356 for(MInt k = 0; k < N; k++) {
357 size += factor * arraySizes[k];
358 }
359
360#ifdef MAIA_ASSERT_ALLOC
361 ASSERT(N > 0 && size > 0, "Error in mAlloc: sizes must be >0, but they are " + std::to_string(N) + " and "
362 + std::to_string(size) + " for " + objectName + " allocated in " + function);
363#endif
364
365 if(N <= 0 || size <= 0) {
366#ifdef MAIA_DEBUG_ALLOC
367 std::cerr << "Error in mAlloc: sizes should be >0, but they are " << std::to_string(N) << " and "
368 << std::to_string(size) << " for " << objectName << " allocated in " << function << std::endl;
369#endif
370 return;
371 }
372
373 a = new T*[N];
374 g_allocatedObjects.push_back(new GenericPointer<T*>(a, objectName, N * sizeof(T*), function, true));
375
376 const MString elementsName = "_elements";
377 maia::alloc::debug(objectName, elementsName);
378
379 T* dummy = new T[size];
380 g_allocatedObjects.push_back(
381 new GenericPointer<T>(dummy, objectName + elementsName, size * sizeof(T), function, true, false));
382
383 size_t cnt = 0;
384 for(MInt i = 0; i < N; i++) {
385 a[i] = (T*)(&(dummy[cnt]));
386 cnt += factor * arraySizes[i];
387 }
388}

◆ mAlloc() [13/14]

template<class T >
void mAlloc ( T **&  a,
const MLong  N,
const MLong  M,
const MString objectName,
const T  initialValue,
MString  function 
)
Author
Lennart Schneiders
Date
08.12.2011

Definition at line 215 of file alloc.h.

215 {
216 using namespace maia::alloc;
217 maia::alloc::debug(objectName);
218 maia::alloc::checkPointer(a, objectName, function);
219
220#ifdef MAIA_ASSERT_ALLOC
221 ASSERT(N > 0 && M > 0, "Error in mAlloc: sizes must be >0, but they are " + std::to_string(N) + " and "
222 + std::to_string(M) + " for " + objectName + " allocated in " + function);
223#endif
224
225 if(N <= 0 || M <= 0) {
226#ifdef MAIA_DEBUG_ALLOC
227 std::cerr << "Error in mAlloc: sizes should be >0, but they are " << std::to_string(N) << " and "
228 << std::to_string(M) << " for " << objectName << " allocated in " << function << std::endl;
229#endif
230 return;
231 }
232
233 a = new T*[N];
234 g_allocatedObjects.push_back(new GenericPointer<T*>(a, objectName, N * sizeof(T*), function, true));
235
236 const MString elementsName = "_elements";
237 maia::alloc::debug(objectName, elementsName);
238
239 T* dummy = new T[N * M];
240 g_allocatedObjects.push_back(
241 new GenericPointer<T>(dummy, objectName + elementsName, N * M * sizeof(T), function, true, false));
242
243 for(MInt i = 0; i < N; i++) {
244 a[i] = (T*)(&(dummy[M * i]));
245 }
246
247#ifndef SKIP_INITIAL_VALUE_ALLOC
248 for(MInt i = 0; i < N * M; i++)
249 dummy[i] = initialValue;
250#endif
251}

◆ mAlloc() [14/14]

template<class T >
void mAlloc ( T **&  a,
const MLong  N,
const MLong  M,
const MString objectName,
MString  function 
)
Author
Lennart Schneiders
Date
08.12.2011

Definition at line 260 of file alloc.h.

260 {
261 using namespace maia::alloc;
262 maia::alloc::debug(objectName);
263 maia::alloc::checkPointer(a, objectName, function);
264
265#ifdef MAIA_ASSERT_ALLOC
266 ASSERT(N > 0 && M > 0, "Error in mAlloc: sizes must be >0, but they are " + std::to_string(N) + " and "
267 + std::to_string(M) + " for " + objectName + " allocated in " + function);
268#endif
269
270 if(N <= 0 || M <= 0) {
271#ifdef MAIA_DEBUG_ALLOC
272 std::cerr << "Error in mAlloc: sizes should be >0, but they are " << std::to_string(N) << " and "
273 << std::to_string(M) << " for " << objectName << " allocated in " << function << std::endl;
274#endif
275 return;
276 }
277
278 a = new T*[N];
279
280 g_allocatedObjects.push_back(new GenericPointer<T*>(a, objectName, N * sizeof(T*), function, true));
281
282 const MString elementsName = "[0]";
283 maia::alloc::debug(objectName, elementsName);
284
285 a[0] = new T[N * M];
286 g_allocatedObjects.push_back(
287 new GenericPointer<T>(a[0], objectName + elementsName, N * M * sizeof(T), function, true, false));
288
289 for(MInt i = 1; i < N; i++) {
290 a[i] = (T*)(&(a[0][M * i]));
291 }
292}

◆ maxAllocatedBytes()

MLong maxAllocatedBytes ( )

Definition at line 123 of file alloc.cpp.

◆ mDealloc()

void mDealloc ( )
Author
Lennart Schneiders
Date
08.12.2011
Author
Lennart Schneiders
Date
08.12.2011

Definition at line 20 of file alloc.cpp.

20 {
21 TRACE();
22 using namespace maia::alloc;
23
24 const MInt padSize = 50;
25 MInt N = 20;
26 std::vector<MString> topConsumers;
27 std::vector<MLong> consumption(N);
28 for(MInt k = 0; k < N; k++) {
29 consumption[k] = 0;
30 topConsumers.emplace_back("-");
31 }
32 MInt count = 0;
33 for(auto i = g_allocatedObjects.begin(); i != g_allocatedObjects.end(); i++) {
34 MLong size = (*i)->getElementSize();
35 MString name = (*i)->getName();
36 auto j = i + 1;
37 while((j != g_allocatedObjects.end()) && ((*j)->getObjectId() == (*i)->getObjectId())) {
38 size += (*j)->getElementSize();
39 j++;
40 i++;
41 }
42 count++;
43 for(MInt k = 0; k < N; k++) {
44 if(size > consumption[k]) {
45 for(MInt l = N - 1; l > k; l--) {
46 consumption[l] = consumption[l - 1];
47 }
48 consumption[k] = size;
49 topConsumers.insert(topConsumers.begin() + k, name);
50 topConsumers.pop_back();
51 k = N;
52 }
53 }
54 }
55
56 N = mMin(N, count);
57
58 for(MInt k = 0; k < padSize + 24; k++) {
59 m_log << "_";
60 }
61 m_log << endl;
62 m_log << "Freeing allocated memory...";
63
65
66 for(auto& g_allocatedObject : g_allocatedObjects) {
67#ifdef MAIA_EXTRA_DEBUG
68 m_log << "Deallocating " << g_allocatedObject->getName() << " " << std::endl;
69 m_log.flush();
70#endif
71 delete g_allocatedObject;
72 }
73 g_allocatedObjects.clear();
74
75 m_log << " finished" << endl;
76 m_log << "Maximum allocated memory was " << getMemorySize(maxAllocatedBytes()) << "." << endl;
77 m_log << endl << "Top " << N << " (out of " << count << ") memory consumers are:" << endl;
78 MChar buffer[100 + padSize];
79 MLong sum = 0;
80 for(MInt k = 0; k < N; k++) {
81 sum += consumption[k];
82 MString name(topConsumers[k], 0, mMin(std::size_t(padSize - 2), topConsumers[k].size()));
83 name += ":";
84 if(padSize > (signed)name.size()) {
85 name.insert(name.end(), padSize - name.size(), ' ');
86 }
87 MString buf0 = name;
88 MString buf1 = getMemorySize(consumption[k]);
89 MFloat perc = 100.0 * ((static_cast<MFloat>(consumption[k])) / (static_cast<MFloat>(maxAllocatedBytes())));
90 sprintf(buffer, "%3d%s %s %s %s%6.2f%s", k + 1, ".", buf0.c_str(), buf1.c_str(), "=", perc, "%");
91 m_log << buffer << endl;
92 }
93 MString tmp;
94 tmp.insert(tmp.end(), padSize + 6, ' ');
95 tmp.insert(tmp.end(), 18, '-');
96 m_log << tmp << endl;
97 MString name;
98 if(padSize > (signed)name.size()) {
99 name.insert(name.end(), padSize - name.size(), ' ');
100 }
101 MString buf0 = name;
102 MString buf1 = getMemorySize(sum);
103 MFloat perc = 100.0 * ((static_cast<MFloat>(sum)) / (static_cast<MFloat>(maxAllocatedBytes())));
104 sprintf(buffer, "%s%s %s %s %s%6.2f%s", " ", " ", buf0.c_str(), buf1.c_str(), "=", perc, "%");
105 m_log << buffer << endl;
106
107 topConsumers.clear();
108
109 if(allocatedBytes() > 0) {
110 m_log << "Uncleared memory: " << getMemorySize(allocatedBytes()) << "." << endl;
111 } else {
112 m_log << "All memory cleared." << endl;
113 }
114 for(MInt k = 0; k < padSize + 24; k++) {
115 m_log << "_";
116 }
117 m_log << endl << endl << endl;
118}
MLong maxAllocatedBytes()
Return the maximum number of allocated bytes.
Definition: alloc.cpp:123
MLong allocatedBytes()
Return the number of allocated bytes.
Definition: alloc.cpp:121
constexpr T mMin(const T &x, const T &y)
Definition: functions.h:90
MString getMemorySize(MLong noBytes)
Returns memory size in KB, MB or GB.
InfoOutFile m_log
double MFloat
Definition: maiatypes.h:52
int64_t MLong
Definition: maiatypes.h:64
char MChar
Definition: maiatypes.h:56

◆ mDeallocate()

template<class T >
MBool mDeallocate ( T *&  a)
Author
Lennart Schneiders
Date
09.12.2011

Definition at line 544 of file alloc.h.

544 {
545 using namespace maia::alloc;
546 if(a == nullptr) {
547#ifdef MAIA_EXTRA_DEBUG
548 m_log << "cannot deallocate zero pointer " << a << std::endl;
549#endif
550 return false;
551 }
552
553 std::vector<GenericObject*>::iterator hit;
554 const MInt count = findAllocatedObject(a, hit);
555
556#ifdef MAIA_EXTRA_DEBUG
557 if(count > 0)
558 m_log << "Deallocating " << (*hit)->getName() << "."
559 << " " << &a << " " << count << std::endl;
560 m_log.flush();
561 if(count > 0)
562 std::cerr << "Deallocating " << (*hit)->getName() << "."
563 << " " << &a << " " << count << std::endl;
564#endif
565
566 if(count <= 0) {
567#ifndef NDEBUG
568 std::cerr << "mDeallocate error: " << count << " " << a << std::endl;
569 if(count == 0) {
570 std::cerr << "Pointer should have been reset to nullptr!" << std::endl;
571 }
572#endif
573 a = nullptr;
574 return false;
575 }
576
577
578 for(MInt k = count; k--;) {
579 delete *(hit + k);
580 }
581
582 if(count == 1)
583 g_allocatedObjects.erase(hit);
584 else if(count > 1)
585 g_allocatedObjects.erase(hit, hit + count);
586
587 if(count > 0) {
588 a = nullptr;
589 }
590
591 return (count > 0);
592}
MInt findAllocatedObject(const T *const a, std::vector< GenericObject * >::iterator &hit)
Find the allocated object for a given pointer.
Definition: alloc.h:63

◆ printAllocatedObjects() [1/2]

void printAllocatedObjects ( )
inline
Author
Julian Vorspohl
Date
20.06.2021

Definition at line 606 of file alloc.h.

606 {
607 for(auto&& obj : maia::alloc::g_allocatedObjects) {
608#ifdef MAIA_EXTRA_DEBUG
609 std::cout << "Name " << obj->getName() << " Function " << obj->getCallingFunction() << std::endl;
610#else
611 std::cout << "Name " << obj->getName() << std::endl;
612#endif
613 }
614 std::cout << "Total number of allocated objects: " << maia::alloc::g_allocatedObjects.size() << std::endl;
615}

◆ printAllocatedObjects() [2/2]

void printAllocatedObjects ( const MString filterString)
inline
Author
Julian Vorspohl
Date
20.06.2021

Definition at line 623 of file alloc.h.

623 {
624 for(auto&& obj : maia::alloc::g_allocatedObjects) {
625 const MString fName = obj->getCallingFunction();
626 const MBool containsFilterString = (fName.find(filterString) != std::string::npos);
627 if(containsFilterString) {
628 std::cout << filterString << ": Memory for " << obj->getName() << " from function " << fName
629 << " should have been deallocated by now!" << std::endl;
630 }
631 }
632}
bool MBool
Definition: maiatypes.h:58