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

#include <UT_MemoryCounter.h>

+ Inheritance diagram for UT_MemoryCounter:

Public Member Functions

 UT_MemoryCounter ()
 
virtual ~UT_MemoryCounter ()
 
virtual void reset ()
 
virtual bool countShared (size_t size, exint refcount, const void *p)
 
void countUnshared (size_t size)
 
virtual size_t getCount () const
 
bool mustCountShared () const
 
bool mustCountUnshared () const
 

Protected Member Functions

 UT_MemoryCounter (const bool countshared, const bool countunshared)
 

Detailed Description

This is the base class of a set of classes for simplifying counting of shared memory for different use cases. The base class counts all shared memory as if it is unshared, thus computing the total amount of memory used by something, assuming that the same block of memory is never referenced more than once.

Examples:
packedshareddata/GU_PackedSharedData.C, packedshareddata/GU_PackedSharedData.h, packedsphere/GU_PackedSphere.C, packedsphere/GU_PackedSphere.h, tetprim/GEO_PrimTetra.C, and tetprim/GEO_PrimTetra.h.

Definition at line 44 of file UT_MemoryCounter.h.

Constructor & Destructor Documentation

UT_MemoryCounter::UT_MemoryCounter ( )
inline

Definition at line 47 of file UT_MemoryCounter.h.

virtual UT_MemoryCounter::~UT_MemoryCounter ( )
inlinevirtual

NOTE: The virtual destructor is needed to destruct subclass members, even if no special destruction is necessary for the subclass itself.

Definition at line 56 of file UT_MemoryCounter.h.

UT_MemoryCounter::UT_MemoryCounter ( const bool  countshared,
const bool  countunshared 
)
inlineprotected

Definition at line 129 of file UT_MemoryCounter.h.

Member Function Documentation

virtual bool UT_MemoryCounter::countShared ( size_t  size,
exint  refcount,
const void p 
)
inlinevirtual

This counts shared memory according to the requirements of the use case. The default implementation counts the total amount of memory referenced by something, assuming the same block is never referenced more than once.

This returns true if the memory counter has recorded this shared memory pointer at least once before. If you have a shared object that itself owns separately shared data, if calling countShared for the outer level of shared data returns true, the inner level of shared data doesn't need to be counted again. For example, when counting the memory of packed primitives, multiple packed primitives may be referencing the same detail, and multiple details may be sharing attribute data, so if the countShared call for the detail handle returns true, the detail doesn't need to be traversed again.

NOTE: Subclasses should NOT call UT_MemoryCounter::countShared().

Reimplemented in UT_MemoryCounterGather, UT_MemoryCounterNewSafe, UT_MemoryCounterNew, UT_MemoryCounterTotal, UT_MemoryCounterFullSafe, UT_MemoryCounterUniqueFullSafe, and UT_MemoryCounterUnique.

Definition at line 83 of file UT_MemoryCounter.h.

void UT_MemoryCounter::countUnshared ( size_t  size)
inline

This counts unshared memory, which doesn't require any special handling.

Examples:
packedshareddata/GU_PackedSharedData.C, packedsphere/GU_PackedSphere.C, and tetprim/GEO_PrimTetra.C.

Definition at line 92 of file UT_MemoryCounter.h.

virtual size_t UT_MemoryCounter::getCount ( ) const
inlinevirtual

This returns the current count of memory used. NOTE: Subclasses should call UT_MemoryCounter::getCount() to get the unshared memory contribution.

Reimplemented in UT_MemoryCounterNewSafe, UT_MemoryCounterNew, and UT_MemoryCounterTotal.

Definition at line 100 of file UT_MemoryCounter.h.

bool UT_MemoryCounter::mustCountShared ( ) const
inline

If this returns false, the code using the UT_MemoryCounter doesn't need to compute memory usage for a complicated object if its refcount > 1.

NOTE: Subclasses must handle shared memory appropriately, even if this is false, to avoid having to always check this.

Definition at line 111 of file UT_MemoryCounter.h.

bool UT_MemoryCounter::mustCountUnshared ( ) const
inline

If this returns false, the code using the UT_MemoryCounter doesn't need to compute memory usage for a complicated object if it is unshared or has refcount == 1.

NOTE: Subclasses must handle memory with refcount==1 appropriately, even if this is false, to avoid having to always check this.

Examples:
packedshareddata/GU_PackedSharedData.C, and packedsphere/GU_PackedSphere.C.

Definition at line 123 of file UT_MemoryCounter.h.

virtual void UT_MemoryCounter::reset ( void  )
inlinevirtual

This resets any data structures used for counting to their freshly-constructed state. NOTE: Subclasses should call UT_MemoryCounter::reset().

Reimplemented in UT_MemoryCounterGather, UT_MemoryCounterNewSafe, UT_MemoryCounterNew, UT_MemoryCounterTotal, UT_MemoryCounterFullSafe, and UT_MemoryCounterUniqueFullSafe.

Definition at line 61 of file UT_MemoryCounter.h.


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