11 #ifndef __UT_MemoryTable__
12 #define __UT_MemoryTable__
74 void set(
size_t amount)
77 myAtomic.exchange(amount);
80 for (
auto &
val : myValue)
90 return myAtomic.relaxedLoad();
93 for (
auto &
val : myValue)
97 size_t add(
size_t amount)
100 return myAtomic.add(amount);
101 auto &
val = myValue.get();
105 size_t sub(
size_t amount)
108 return myAtomic.add(-amount);
109 auto &
val = myValue.get();
113 size_t max(
size_t amount)
116 return myAtomic.maximum(amount);
117 auto &
val = myValue.get();
129 : myUsed(use_atomics)
130 , myPeak(use_atomics)
140 size_t getUsed()
const {
return myUsed.get(); }
141 size_t getPeak()
const {
return myPeak.get(); }
142 void inc(
size_t amount) { myPeak.max(myUsed.add(amount)); }
143 void dec(
size_t amount) { myUsed.sub(amount); }
164 mySize = number_of_users;
171 size_t getUsed()
const;
172 size_t getPeak()
const;
174 void inc(
int user,
size_t amount)
176 myTable[user].inc(amount);
178 void dec(
int user,
size_t amount)
180 myTable[user].dec(amount);
200 table.
inc(which_entry, amount);
201 return malloc(amount);
214 table.
inc(which_entry, amount);
215 return calloc(1, amount);
226 void *original_memory,
238 table.
dec(which_entry, old_amount);
239 table.
inc(which_entry, new_amount);
240 mem = realloc(original_memory, new_amount);
244 table.
inc(which_entry, new_amount);
245 mem = malloc(new_amount);
253 table.
dec(which_entry, old_amount);
254 free(original_memory);
271 table.
dec(which_entry, amount);
281 table.
inc(which_entry, amount);
288 table.
dec(which_entry, amount);
303 #define UT_MEMORY_SUBCLASS(STATIC, prefix, table) \
304 STATIC void *prefix##Malloc(int i, size_t amount) \
305 { return UT_MemoryAPI::Malloc(table, i, amount); } \
306 STATIC void *prefix##Calloc(int i, size_t amount) \
307 { return UT_MemoryAPI::Calloc(table, i, amount); } \
308 STATIC void *prefix##Realloc(int i, void *m, size_t o, size_t n) \
309 { return UT_MemoryAPI::Realloc(table, i, m, o, n); } \
310 STATIC void prefix##Free(int i, void *m, size_t amount) \
311 { UT_MemoryAPI::Free(table, i, m, amount); } \
312 STATIC void prefix##acquire(int i, size_t amount) \
313 { UT_MemoryAPI::acquire(table, i, amount); } \
314 STATIC void prefix##release(int i, size_t amount) \
315 { UT_MemoryAPI::release(table, i, amount); } \
316 static inline UT_MemoryTable &prefix##getTable() { return table; }
321 #define UT_MEMPRINTSIZE 32
GLsizei GLenum GLsizei GLsizei GLuint memory
GLenum GLuint GLenum GLsizei const GLchar * buf
const UT_MemoryUser & getUser(int index) const
UT_MemoryUser & getUser(int index)
GLuint GLsizei const GLchar * label
void inc(int user, size_t amount)
static void Free(UT_MemoryTable &table, int which_entry, void *memory, size_t amount)
const char * getLabel() const
static void * Malloc(UT_MemoryTable &table, int which_entry, size_t amount)
static void * Calloc(UT_MemoryTable &table, int which_entry, size_t amount)
static void * Realloc(UT_MemoryTable &table, int which_entry, void *original_memory, size_t old_amount, size_t new_amount)
ImageBuf OIIO_API sub(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
static void acquire(UT_MemoryTable &table, int which_entry, size_t amount)
Track a memory acquisition that wasn't performed by this class.
constexpr auto set(type rhs) -> int
UT_MemoryUser(const char *label, bool use_atomics=false)
GLenum GLenum GLsizei void * table
UT_MemoryTable(UT_MemoryUser *user_list, int number_of_users)
void setUsedPeak(size_t used, size_t peak)
Forcibly set values - not typical usage, but required in some cases.
UT_API void UTprintMemory(char buf[UT_MEMPRINTSIZE], int64 memory, int field_width=-1)
void dec(int user, size_t amount)
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
ImageBuf OIIO_API add(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
static void release(UT_MemoryTable &table, int which_entry, size_t amount)
Track a memory free that wasn't performed by this class.