24 const MInt padSize = 50;
26 std::vector<MString> topConsumers;
27 std::vector<MLong> consumption(N);
28 for(
MInt k = 0; k < N; k++) {
30 topConsumers.emplace_back(
"-");
33 for(
auto i = g_allocatedObjects.begin(); i != g_allocatedObjects.end(); i++) {
34 MLong size = (*i)->getElementSize();
37 while((j != g_allocatedObjects.end()) && ((*j)->getObjectId() == (*i)->getObjectId())) {
38 size += (*j)->getElementSize();
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];
48 consumption[k] = size;
49 topConsumers.insert(topConsumers.begin() + k, name);
50 topConsumers.pop_back();
58 for(
MInt k = 0; k < padSize + 24; k++) {
62 m_log <<
"Freeing allocated memory...";
64 reverse(g_allocatedObjects.begin(), g_allocatedObjects.end());
66 for(
auto& g_allocatedObject : g_allocatedObjects) {
67#ifdef MAIA_EXTRA_DEBUG
68 m_log <<
"Deallocating " << g_allocatedObject->getName() <<
" " << std::endl;
71 delete g_allocatedObject;
73 g_allocatedObjects.clear();
75 m_log <<
" finished" << endl;
77 m_log << endl <<
"Top " << N <<
" (out of " << count <<
") memory consumers are:" << endl;
78 MChar buffer[100 + padSize];
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()));
84 if(padSize > (
signed)name.size()) {
85 name.insert(name.end(), padSize - name.size(),
' ');
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;
94 tmp.insert(tmp.end(), padSize + 6,
' ');
95 tmp.insert(tmp.end(), 18,
'-');
98 if(padSize > (
signed)name.size()) {
99 name.insert(name.end(), padSize - name.size(),
' ');
104 sprintf(buffer,
"%s%s %s %s %s%6.2f%s",
" ",
" ", buf0.c_str(), buf1.c_str(),
"=", perc,
"%");
105 m_log << buffer << endl;
107 topConsumers.clear();
112 m_log <<
"All memory cleared." << endl;
114 for(
MInt k = 0; k < padSize + 24; k++) {
117 m_log << endl << endl << endl;
MLong maxAllocatedBytes()
Return the maximum number of allocated bytes.
void mDealloc()
Deallocates all memory allocated previously by mAlloc(...)
MLong allocatedBytes()
Return the number of allocated bytes.
constexpr T mMin(const T &x, const T &y)
MString getMemorySize(MLong noBytes)
Returns memory size in KB, MB or GB.
std::basic_string< char > MString
MLong g_maxAllocatedBytes