Raven Engine v0.1
Loading...
Searching...
No Matches
MemoryTracker.h File Reference
#include "Raven/Core/Logging.h"
#include "Raven/Core/Types.h"
#include <cstdlib>
#include <iostream>
#include <mutex>
#include <unordered_map>
#include <new>
#include <string>

Classes

struct  Raven::MemoryTracker::AllocationInfo
 Struct to hold memory allocation information. More...

Namespaces

namespace  Raven
namespace  Raven::MemoryTracker

Macros

#define rnew   new (__FUNCTION__)
 Macro for memory allocation with tracking.
#define rdelete(ptr)
 Macro for memory deallocation with tracking.
#define rdelete_array(ptr)
 Macro for array memory deallocation with tracking.

Functions

void Raven::MemoryTracker::AddAllocation (void *ptr, usize size, const char *function)
 Mutex for thread-safety when accessing the allocation map.
void Raven::MemoryTracker::RemoveAllocation (void *ptr)
 Remove a memory allocation from the tracker.
void Raven::MemoryTracker::DumpLeaks ()
 Dump memory leaks, if any.
void * operator new (size_t size, const char *function)
 Overload for new operator with function tracking.
void * operator new[] (size_t size, const char *function)
 Overload for new[] operator with function tracking.
void operator delete (void *ptr, const char *) noexcept
 Overload for delete operator with function tracking.
void operator delete[] (void *ptr, const char *) noexcept
 Overload for delete[] operator with function tracking.

Variables

std::unordered_map< void *, AllocationInfoRaven::MemoryTracker::s_Allocations
std::mutex Raven::MemoryTracker::s_Mutex
 Global map tracking allocations.

Macro Definition Documentation

◆ rdelete

#define rdelete ( ptr)
Value:
if (ptr) \
{ \
Raven::MemoryTracker::RemoveAllocation(ptr); /* Unregister before delete */ \
delete ptr; \
}

Macro for memory deallocation with tracking.

This macro ensures memory is properly tracked when being deallocated.

Parameters
ptrPointer to the memory to be freed.

◆ rdelete_array

#define rdelete_array ( ptr)
Value:
do \
{ \
if (ptr) \
{ \
Raven::MemoryTracker::RemoveAllocation(ptr); /* Unregister before delete[] */ \
delete[] ptr; \
} \
} while (0)

Macro for array memory deallocation with tracking.

This macro ensures memory for arrays is properly tracked when being deallocated.

Parameters
ptrPointer to the array of memory to be freed.

◆ rnew

#define rnew   new (__FUNCTION__)

Macro for memory allocation with tracking.

This macro allows for allocation with the tracking of the calling function.

Function Documentation

◆ operator delete()

void operator delete ( void * ptr,
const char *  )
inlinenoexcept

Overload for delete operator with function tracking.

Frees memory and removes the allocation from the tracker.

Parameters
ptrPointer to the memory to be freed.

◆ operator delete[]()

void operator delete[] ( void * ptr,
const char *  )
inlinenoexcept

Overload for delete[] operator with function tracking.

Frees an array of memory and removes the allocation from the tracker.

Parameters
ptrPointer to the array of memory to be freed.

◆ operator new()

void * operator new ( size_t size,
const char * function )
inline

Overload for new operator with function tracking.

Allocates memory and adds the allocation to the tracker, including the function where the allocation was made.

Parameters
sizeSize of the memory to allocate.
functionThe function where the allocation is taking place.
Returns
Pointer to the allocated memory.

◆ operator new[]()

void * operator new[] ( size_t size,
const char * function )
inline

Overload for new[] operator with function tracking.

Allocates an array of memory and adds the allocation to the tracker, including the function where the allocation was made.

Parameters
sizeSize of the memory to allocate.
functionThe function where the allocation is taking place.
Returns
Pointer to the allocated array of memory.