class RED::MemoryLeakTracker
Memory leak tracker class. More...
#include <REDMemoryLeakTracker.h>
Public classes:
class | MemInfos |
Public functions:
MemoryLeakTracker ( ) | |
~MemoryLeakTracker ( ) | |
RED_RC | DumpAllocations ( bool iPanel ) |
const RED::Map< const void *, RED::MemoryLeakTracker::MemInfos > & | GetMemoryInformations ( ) const |
size_t | GetTotalAllocations ( ) const |
bool | IsLiveAddress ( void * iAddress ) const |
void | RecordAllocInfo ( void * iAddress, size_t iSize, int iCallerID ) |
void | RemoveAllocInfo ( const void * iAddress ) |
RED_RC | SetDumpFolder ( const RED::String & iDumpFolder ) |
void | SetUserTrackingCallback ( USER_MLT_CALLBACK iMLTCallback, void * iUserData ) |
Public typedefs:
typedef void(* | USER_MLT_CALLBACK )(bool iOperation, const void *iAddress, size_t iSize, int iAllocationNumber, int iCallerID, void *iUserData) |
Protected variables:
size_t | _allocated |
RED::String | _folder |
RED::Map< const void *, MemInfos > | _meminfos |
USER_MLT_CALLBACK | _mltcb |
void * | _mltcb_user_data |
RED::Mutex * | _mutex |
bool | _norecurse |
Protected static variables:
static unsigned int | _alloc_count |
Detailed description:
Memory leak tracker class.
This class records all allocations that have been done using REDsdk's special allocation calls 'rnew', 'rmalloc', 'rrealloc' or 'rdelete'. Standard 'new' and 'delete' calls are also tracked, but only for all RED::Object inherited classes.
See the RED::MemoryAllocator class for details. Using these calls, the allocated memory is recorded by the memory leak tracker. All REDsdk's internal calls are going through this mechanism as well, making the memory leak tracker an efficient tool for keeping an eye over the total memory being allocated by the engine at a time.
A user can add it's own callback to be notified of each memory operation.
Functions documentation
Default constructor.
Destructor.
public RED_RC RED::MemoryLeakTracker::DumpAllocations | ( | bool | iPanel | ) |
Dumps all allocations.
All allocations are dumped into a file called 'memory_report.txt' in the current application execution folder, unless specified otherwise through the REDMemoryLeakTracker::SetDumpFolder method.
Parameters:
iPanel: | If true, dump a panel with an OK button prompt that contains a summary of all allocations. The panel is displayed in addition to the file dump. |
Returns:
RED_ALLOC_FAILURE if an internal allocation has failed,
RED_FAIL if an error has occurred.
public const RED::Map< const void *, RED::MemoryLeakTracker::MemInfos > & RED::MemoryLeakTracker::GetMemoryInformations | ( | ) const |
public size_t RED::MemoryLeakTracker::GetTotalAllocations | ( | ) const |
Returns the current amount of allocated memory.
Returns:
public bool RED::MemoryLeakTracker::IsLiveAddress | ( | void * | iAddress | ) const |
Tests a single address for existence.
Please note that many memory allocations of deleted objects (for instance using the RED::Factory) are not effectively released by REDsdk until a call to RED::IResourceManager::EndState has occurred.
Parameters:
iAddress: | Address to test. |
Returns:
public void RED::MemoryLeakTracker::RecordAllocInfo | ( | void * | iAddress, |
size_t | iSize, | ||
int | iCallerID | ||
) |
Tracks an allocation.
Parameters:
iAddress: | Address of the allocation. |
iSize: | Byte size of the allocation. |
iCallerID: | Identifier of the allocation caller. |
public void RED::MemoryLeakTracker::RemoveAllocInfo | ( | const void * | iAddress | ) |
Removes an allocation from the storage.
Parameters:
iAddress: | Memory address that has been released. |
public RED_RC RED::MemoryLeakTracker::SetDumpFolder | ( | const RED::String & | iDumpFolder | ) |
Defines the folder used to save the 'memory_report.txt' file.
The folder in which the dump file is saved is by default set to the current application folder. This location can be changed thanks to this method.
Parameters:
iDumpFolder: | The complete path to the dump folder. |
Returns:
RED_ALLOC_FAILURE if an internal allocation has failed,
RED_FAIL if an error has occurred.
public void RED::MemoryLeakTracker::SetUserTrackingCallback | ( | USER_MLT_CALLBACK | iMLTCallback, |
void * | iUserData | ||
) |
Defines the user memory tracking method.
This lets the user be notified of every memory operation inside the engine.
Parameters:
iMLTCallback: | The new callback. NULL to invalidate the current callback. |
iUserData: | The user data associated with the callback. |
Variables documentation
Total memory currently allocated by our allocator.
File dump folder.
Map of the recorded memory operations.
User memory operation notification callback.
User data associated with the notification callback.
Mutex to guarantee multi-threading safety.
Used to avoid Map re-entrance in the tracker.
Allocation counter.
Types documentation
Prototype of the user memory tracking callback.
Defines the prototype of the user memory tracking callback. When the callback is set, the user is notified of each memory change that is tracked by the memory leak tracker.
Please note that the 'iAllocationNumber' that provides the number of the allocation since the program start is only reliable in non-multi threaded environments. Therefore, if the application renders using one of the engine ray-tracers with more than one single calculation thread, the allocation number may change.
Parameters:
iOperation: | Memory operation code. true: allocation. false: release. |
iAddress: | Address affected by the operation. |
iSize: | Byte size of the operation. |
iAllocationNumber: | Number of the recorded allocation since the program execution start. |
iCallerID: | Identifier of the operation's caller. |
iUserData: | Custom user data get from RED::MemoryLeakTracker::SetUserTrackingCallback. |