11 #ifndef __SYS_Memory__
12 #define __SYS_Memory__
73 : myUsed(rhs.myUsed.relaxedLoad())
74 , myPeak(rhs.myPeak.relaxedLoad())
76 myLabel = rhs.myLabel;
79 const char *
getLabel()
const {
return myLabel; }
83 void inc(
size_t amount)
85 myPeak.maximum(myUsed.add(amount));
87 void dec(
size_t amount)
103 mySize = number_of_users;
110 size_t getUsed()
const;
111 size_t getPeak()
const;
113 void inc(
int user,
size_t amount)
115 myTable[user].inc(amount);
117 void dec(
int user,
size_t amount)
119 myTable[user].dec(amount);
138 table.
inc(which_entry, amount);
139 return malloc(amount);
152 table.
inc(which_entry, amount);
153 return calloc(1, amount);
164 void *original_memory,
176 table.
dec(which_entry, old_amount);
177 table.
inc(which_entry, new_amount);
178 mem = realloc(original_memory, new_amount);
182 table.
inc(which_entry, new_amount);
183 mem = malloc(new_amount);
191 table.
dec(which_entry, old_amount);
192 free(original_memory);
209 table.
dec(which_entry, amount);
219 table.
inc(which_entry, amount);
226 table.
dec(which_entry, amount);
241 #define SYS_MEMORY_SUBCLASS(STATIC, prefix, table) \
242 STATIC void *prefix##Malloc(int i, size_t amount) \
243 { return SYS_Memory::Malloc(table, i, amount); } \
244 STATIC void *prefix##Calloc(int i, size_t amount) \
245 { return SYS_Memory::Calloc(table, i, amount); } \
246 STATIC void *prefix##Realloc(int i, void *m, size_t o, size_t n) \
247 { return SYS_Memory::Realloc(table, i, m, o, n); } \
248 STATIC void prefix##Free(int i, void *m, size_t amount) \
249 { SYS_Memory::Free(table, i, m, amount); } \
250 STATIC void prefix##acquire(int i, size_t amount) \
251 { SYS_Memory::acquire(table, i, amount); } \
252 STATIC void prefix##release(int i, size_t amount) \
253 { SYS_Memory::release(table, i, amount); } \
254 static inline SYS_MemoryTable &prefix##getTable() { return table; }
260 #define SYS_MEMPRINTSIZE 32
SYS_API void SYSprintMemory(char buf[SYS_MEMPRINTSIZE], int64 memory, int field_width=-1)
GLuint GLsizei const GLchar * label
static void release(SYS_MemoryTable &table, int which_entry, size_t amount)
Track a memory free that wasn't performed by this class.
SYS_MemoryUser(const SYS_MemoryUser &rhs)
const SYS_MemoryUser & getUser(int index) const
static void Free(SYS_MemoryTable &table, int which_entry, void *memory, size_t amount)
SYS_MemoryUser & getUser(int index)
static void * Realloc(SYS_MemoryTable &table, int which_entry, void *original_memory, size_t old_amount, size_t new_amount)
static void * Calloc(SYS_MemoryTable &table, int which_entry, size_t amount)
void inc(int user, size_t amount)
GLenum GLuint GLenum GLsizei const GLchar * buf
SYS_MemoryUser(const char *label)
SYS_MemoryTable(SYS_MemoryUser *user_list, int number_of_users)
static void acquire(SYS_MemoryTable &table, int which_entry, size_t amount)
Track a memory acquisition that wasn't performed by this class.
static void * Malloc(SYS_MemoryTable &table, int which_entry, size_t amount)
const char * getLabel() const
void dec(int user, size_t amount)