Scoped (i.e. More...
Public Member Functions | |
Auto (const Auto &)=delete | |
Auto & | operator= (const Auto &)=delete |
Auto (Auto &&)=delete | |
Auto & | operator= (Auto &&)=delete |
Auto (const char *name) | |
Push a memory tag onto the local-call stack with name name . More... | |
Auto (const std::string &name) | |
Push a memory tag onto the local-call stack with name name . More... | |
void | Release () |
Pop the tag from the stack before it is destructed. More... | |
~Auto () | |
Pop a memory tag from the local-call stack. More... | |
Friends | |
class | TfMallocTag |
Scoped (i.e.
local) object for creating/destroying memory tags.
Note: TfAutoMallocTag
is a typedef to TfMallocTag::Auto
; the convention is to use TfAutoMallocTag
to make it clear that the local object exists only because its constructor and destructor modify program state.
A TfAutoMallocTag
object is used to push a memory tag onto the current call stack; destruction of the object pops the call stack. Note that each thread has its own call-stack.
There is no (measurable) cost to creating or destroying memory tags if TfMallocTag::Initialize()
has not been called; if it has, then there is a small (but measurable) cost associated with pushing and popping memory tags on the local call stack. Most of the cost is simply locking a mutex; typically, pushing or popping the call stack does not actually cause any memory allocation unless this is the first time that the given named tag has been encountered.
Definition at line 262 of file mallocTag.h.
|
inline |
Push a memory tag onto the local-call stack with name name
.
If TfMallocTag::Initialize()
has not been called, this constructor does essentially no (measurable) work, assuming name
is a string literal or just a pointer to an existing string.
Objects of this class should only be created as local variables; never as member variables, global variables, or via new
. If you can't create your object as a local variable, you can make manual calls to TfMallocTag::Push()
and TfMallocTag::Pop()
, though you should do this only as a last resort.
Definition at line 281 of file mallocTag.h.
|
inline |
Push a memory tag onto the local-call stack with name name
.
If TfMallocTag::Initialize()
has not been called, this constructor does essentially no (measurable) work. However, any work done in constructing the std::string
object name
will be incurred even if tagging is not active. If this is an issue, you can query TfMallocTag::IsInitialized()
to avoid unneeded work when tagging is inactive. Note that the case when name
is a string literal does not apply here: instead, the constructor that takes a const
char*
(above) will be called.
Objects of this class should only be created as local variables; never as member variables, global variables, or via new
. If you can't create your object as a local variable, you can make manual calls to TfMallocTag::Push()
and TfMallocTag::Pop()
, though you should do this only as a last resort.
Definition at line 302 of file mallocTag.h.
|
inline |
Pop a memory tag from the local-call stack.
If TfMallocTag::Initialize()
was not called when this tag was pushed onto the stack, popping the tag from the stack does essentially no (measurable) work.
Definition at line 329 of file mallocTag.h.
|
inline |
Pop the tag from the stack before it is destructed.
Normally you should not use this. The normal destructor is preferable because it insures proper release order. If you call Release()
, make sure all tags are released in the opposite order they were declared in. It is better to use sub-scopes to control the life span of tags, but if that won't work, Release()
is still preferable to TfMallocTag::Push()
and TfMallocTag::Pop()
because it isn't vulnerable to early returns or exceptions.
Definition at line 317 of file mallocTag.h.