ManaPlus
Public Member Functions
MemoryManager Class Reference

#include <memorymanager.h>

Public Member Functions

 MemoryManager ()
 
 ~MemoryManager ()
 
int getSurfaceSize (const SDL_Surface *const surface)
 
void printMemory (const std::string &name, const int level, const int localSum, const int childsSum)
 
void printAllMemory (ChatTab *const tab)
 

Detailed Description

Definition at line 32 of file memorymanager.h.

Constructor & Destructor Documentation

◆ MemoryManager()

MemoryManager::MemoryManager ( )

Definition at line 39 of file memorymanager.cpp.

40 {
41 }

◆ ~MemoryManager()

MemoryManager::~MemoryManager ( )
inline

Definition at line 39 of file memorymanager.h.

References getSurfaceSize(), memoryManager, printAllMemory(), and printMemory().

40  { }

Member Function Documentation

◆ getSurfaceSize()

int MemoryManager::getSurfaceSize ( const SDL_Surface *const  surface)

Definition at line 44 of file memorymanager.cpp.

References CAST_S32.

Referenced by Image::calcMemoryLocal(), ResourceManager::calcMemoryLocal(), and ~MemoryManager().

45 {
46  if (surface == nullptr)
47  return 0;
48  return CAST_S32(sizeof(SDL_Surface)) +
49  CAST_S32(sizeof(SDL_PixelFormat)) +
50  // aproximation for sizeof(SDL_BlitMap)
51  28 +
52  // pixels
53  surface->w * surface->h * 4 +
54  // private_hdata aproximation
55  10;
56 }
#define CAST_S32
Definition: cast.h:29

◆ printAllMemory()

void MemoryManager::printAllMemory ( ChatTab *const tab  A_DYECMD_UNUSED)

Definition at line 82 of file memorymanager.cpp.

References _, ChatMsgType::BY_SERVER, ResourceManager::calcMemory(), logger, and strprintf().

Referenced by Actions::doSit(), and ~MemoryManager().

83 {
84  if (logger == nullptr)
85  return;
86 
87 #ifdef DYECMD
89 #else // DYECMD
90 
91  int sz = ResourceManager::calcMemory(0);
92  if (tab != nullptr)
93  {
94  // TRANSLATORS: memory usage chat message
95  tab->chatLog(strprintf(_("Calculated memory usage: %d"), sz),
97  }
98 #endif // DYECMD
99 }
#define _(s)
Definition: gettext.h:34
int calcMemory(const int level)
Logger * logger
Definition: logger.cpp:95
std::string strprintf(const char *const format,...)
Definition: stringutils.cpp:99

◆ printMemory()

void MemoryManager::printMemory ( const std::string &  name,
const int  level,
const int  localSum,
const int  childsSum 
)

Definition at line 58 of file memorymanager.cpp.

References Logger::log(), logger, and ServerCommandType::str.

Referenced by MemoryCounter::calcMemory(), ResourceManager::calcMemory(), and ~MemoryManager().

62 {
63  std::string str(level, ' ');
64  if (childsSum > 0)
65  {
66  logger->log("%s%s: %d = %d + %d",
67  str.c_str(),
68  name.c_str(),
69  localSum + childsSum,
70  localSum,
71  childsSum);
72  }
73  else
74  {
75  logger->log("%s%s: %d",
76  str.c_str(),
77  name.c_str(),
78  localSum);
79  }
80 }
Logger * logger
Definition: logger.cpp:95
void log(const char *const log_text,...)
Definition: logger.cpp:243

The documentation for this class was generated from the following files: