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

Go to the source code of this file.

Functions

void mDealloc ()
 Deallocates all memory allocated previously by mAlloc(...) More...
 
MLong allocatedBytes ()
 Return the number of allocated bytes. More...
 
MLong maxAllocatedBytes ()
 Return the maximum number of allocated bytes. More...
 

Function Documentation

◆ allocatedBytes()

MLong allocatedBytes ( )

Definition at line 121 of file alloc.cpp.

◆ maxAllocatedBytes()

MLong maxAllocatedBytes ( )

Definition at line 123 of file alloc.cpp.

◆ mDealloc()

void mDealloc ( )
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
int32_t MInt
Definition: maiatypes.h:62
std::basic_string< char > MString
Definition: maiatypes.h:55
double MFloat
Definition: maiatypes.h:52
int64_t MLong
Definition: maiatypes.h:64
char MChar
Definition: maiatypes.h:56
std::vector< GenericObject * > g_allocatedObjects