ManaPlus
Public Member Functions | Static Public Member Functions
MemoryManager Class Reference

#include <memorymanager.h>

Public Member Functions

 MemoryManager ()
 
 ~MemoryManager ()
 

Static Public Member Functions

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

Detailed Description

Definition at line 33 of file memorymanager.h.

Constructor & Destructor Documentation

◆ MemoryManager()

MemoryManager::MemoryManager ( )

Definition at line 40 of file memorymanager.cpp.

41 {
42 }

◆ ~MemoryManager()

MemoryManager::~MemoryManager ( )
inline

Definition at line 40 of file memorymanager.h.

41  { }

Member Function Documentation

◆ getSurfaceSize()

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

Definition at line 45 of file memorymanager.cpp.

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

References CAST_S32.

Referenced by ResourceManager::calcMemoryLocal().

◆ printAllMemory()

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

Definition at line 83 of file memorymanager.cpp.

84 {
85  if (logger == nullptr)
86  return;
87 
88 #ifdef DYECMD
90 #else // DYECMD
91 
92  if (tab != nullptr)
93  {
94  int sz = ResourceManager::calcMemory(0);
95  // TRANSLATORS: memory usage chat message
96  tab->chatLog(strprintf(_("Calculated memory usage: %d"), sz),
100  }
101 #endif // DYECMD
102 }
#define _(s)
Definition: gettext.h:35
const bool IgnoreRecord_false
Definition: ignorerecord.h:30
Logger * logger
Definition: logger.cpp:89
int calcMemory(const int level)
std::string strprintf(const char *const format,...)
const bool TryRemoveColors_true

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

◆ printMemory()

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

Definition at line 59 of file memorymanager.cpp.

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

References Logger::log(), and logger.

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


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