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; }
80 size_t getUsed()
const {
return myUsed.relaxedLoad(); }
81 size_t getPeak()
const {
return myPeak.relaxedLoad(); }
83 void inc(
size_t amount)
85 myPeak.maximum(myUsed.add(amount));
87 void dec(
size_t amount)
95 myUsed.exchange(used);
96 myPeak.exchange(peak);
110 mySize = number_of_users;
117 size_t getUsed()
const;
118 size_t getPeak()
const;
120 void inc(
int user,
size_t amount)
122 myTable[user].inc(amount);
124 void dec(
int user,
size_t amount)
126 myTable[user].dec(amount);
145 table.
inc(which_entry, amount);
146 return malloc(amount);
159 table.
inc(which_entry, amount);
160 return calloc(1, amount);
171 void *original_memory,
183 table.
dec(which_entry, old_amount);
184 table.
inc(which_entry, new_amount);
185 mem = realloc(original_memory, new_amount);
189 table.
inc(which_entry, new_amount);
190 mem = malloc(new_amount);
198 table.
dec(which_entry, old_amount);
199 free(original_memory);
216 table.
dec(which_entry, amount);
226 table.
inc(which_entry, amount);
233 table.
dec(which_entry, amount);
248 #define SYS_MEMORY_SUBCLASS(STATIC, prefix, table) \
249 STATIC void *prefix##Malloc(int i, size_t amount) \
250 { return SYS_Memory::Malloc(table, i, amount); } \
251 STATIC void *prefix##Calloc(int i, size_t amount) \
252 { return SYS_Memory::Calloc(table, i, amount); } \
253 STATIC void *prefix##Realloc(int i, void *m, size_t o, size_t n) \
254 { return SYS_Memory::Realloc(table, i, m, o, n); } \
255 STATIC void prefix##Free(int i, void *m, size_t amount) \
256 { SYS_Memory::Free(table, i, m, amount); } \
257 STATIC void prefix##acquire(int i, size_t amount) \
258 { SYS_Memory::acquire(table, i, amount); } \
259 STATIC void prefix##release(int i, size_t amount) \
260 { SYS_Memory::release(table, i, amount); } \
261 static inline SYS_MemoryTable &prefix##getTable() { return table; }
267 #define SYS_MEMPRINTSIZE 32
GLsizei GLenum GLsizei GLsizei GLuint memory
SYS_API void SYSprintMemory(char buf[SYS_MEMPRINTSIZE], int64 memory, int field_width=-1)
GLenum GLuint GLenum GLsizei const GLchar * buf
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)
GLenum GLenum GLsizei void * table
void inc(int user, size_t amount)
void setUsedPeak(size_t used, size_t peak)
Forcibly set values - not typical usage, but required in some cases.
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)