MemoryLeakTracker
Type Aliases
void(* | USER_MLT_CALLBACK |
Functions
MemoryLeakTracker |
|
~MemoryLeakTracker |
|
void | RecordAllocInfo |
void | RemoveAllocInfo |
void | SetUserTrackingCallback |
bool | IsLiveAddress |
size_t | GetTotalAllocations |
const Map < const void *, MemInfos > & | GetMemoryInformations |
RED_RC |
DumpAllocations |
RED_RC |
SetDumpFolder |
Detailed Description
-
class
MemoryLeakTracker
Memory leak tracker class.
@related Backbone, class RED::MemoryAllocator
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.
Public Types
-
typedef void (*
USER_MLT_CALLBACK
)(bool iOperation, const void *iAddress, size_t iSize, int iAllocationNumber, int iCallerID, void *iUserData) 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.
Param iOperation: Memory operation code. true: allocation. false: release. Param iAddress: Address affected by the operation. Param iSize: Byte size of the operation. Param iAllocationNumber: Number of the recorded allocation since the program execution start. Param iCallerID: Identifier of the operation’s caller. Param iUserData: Custom user data get from RED::MemoryLeakTracker::SetUserTrackingCallback.
Public Functions
-
MemoryLeakTracker
() Default constructor.
-
~MemoryLeakTracker
() Destructor.
-
void
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.
-
void
RemoveAllocInfo
(const void *iAddress) Removes an allocation from the storage.
Parameters: iAddress – Memory address that has been released.
-
void
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.
-
bool
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: true if the address exists, false otherwise.
-
inline size_t
GetTotalAllocations
() const Returns the current amount of allocated memory.
Returns: The total number of allocated bytes through the RED::MemoryAllocator.
-
inline const RED::Map<const void*, RED::MemoryLeakTracker::MemInfos> &
GetMemoryInformations
() const Returns all memory information.
Returns: The RED::Map used to store all currently live allocations.
-
RED_RC
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_OK if the operation has succeeded, RED_ALLOC_FAILURE if an internal allocation has failed,
RED_FAIL if an error has occurred.
-
RED_RC
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_OK if the operation has succeeded, RED_ALLOC_FAILURE if an internal allocation has failed,
RED_FAIL if an error has occurred.
-
class
MemInfos
Data record for a memory allocation.
@related Backbone, class RED::MemoryLeakTracker, class RED::MemoryAllocator
-
typedef void (*