HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_MemoryUser Class Reference

#include <UT_MemoryTable.h>

+ Inheritance diagram for UT_MemoryUser:

Public Member Functions

 UT_MemoryUser (const char *label, bool use_atomics=false)
 
const char * getLabel () const
 
size_t getUsed () const
 
size_t getPeak () const
 
void inc (size_t amount)
 
void dec (size_t amount)
 
void setUsedPeak (size_t used, size_t peak)
 Forcibly set values - not typical usage, but required in some cases. More...
 

Additional Inherited Members

- Protected Member Functions inherited from UT_NonCopyableNS::UT_NonCopyable
 UT_NonCopyable ()=default
 
 ~UT_NonCopyable ()=default
 
 UT_NonCopyable (const UT_NonCopyable &)=delete
 
UT_NonCopyableoperator= (const UT_NonCopyable &)=delete
 

Detailed Description

Memory Tracking

This class provides a mechanism for tracking memory usage. If all memory allocation and freeing is registered with this class, then the memory footprint and resource usage can be tracked.

There is a companion class at UT which allows for printing of the memory statistics.

An example of how to use this might be:

enum { MEM_DEBUG = 0, MEM_TASK1, MEM_TASK2, MEM_MAX_TASKS };

static UT_MemoryUser theMemoryUsers[MEM_MAX_TASKS] = { UT_MemoryUser("Debug), UT_MemoryUser("Task One"), UT_MemoryUser("Task Two"), };

static UT_MemoryTable theMemoryTable(theMemoryUsers, sizeof(theMemoryUsers)/sizeof(UT_MemoryTable));

int main(int argc, char *argv[]) { UT_WorkBuffer stats; void *mem; mem = UT_Memory::Malloc(theMemoryTable, MEM_TASK1, 128); mem = UT_Memory::Realloc(theMemoryTable, MEM_TASK1, mem, 128, 256); UT_Memory::Free(theMemoryTable, MEM_TASK1, mem, 256); UT_Memory::printTable(stats, theMemoryTable); cout << stats.buffer(); return 0; }

Definition at line 64 of file UT_MemoryTable.h.

Constructor & Destructor Documentation

UT_MemoryUser::UT_MemoryUser ( const char *  label,
bool  use_atomics = false 
)
inline

Definition at line 128 of file UT_MemoryTable.h.

Member Function Documentation

void UT_MemoryUser::dec ( size_t  amount)
inline

Definition at line 143 of file UT_MemoryTable.h.

const char* UT_MemoryUser::getLabel ( ) const
inline

Definition at line 136 of file UT_MemoryTable.h.

size_t UT_MemoryUser::getPeak ( ) const
inline

Definition at line 141 of file UT_MemoryTable.h.

size_t UT_MemoryUser::getUsed ( ) const
inline

Note that getUsed() and getPeak() may not be thread-safe unless initialized with use_atomics = true

Definition at line 140 of file UT_MemoryTable.h.

void UT_MemoryUser::inc ( size_t  amount)
inline

Definition at line 142 of file UT_MemoryTable.h.

void UT_MemoryUser::setUsedPeak ( size_t  used,
size_t  peak 
)
inline

Forcibly set values - not typical usage, but required in some cases.

Definition at line 146 of file UT_MemoryTable.h.


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