summaryrefslogtreecommitdiff
path: root/Runtime/Allocator/MemoryMacros.cpp
blob: 75daeb88444a2fb4468e21aad45b9679f2d3d392 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "UnityPrefix.h"
#include "Runtime/Profiler/MemoryProfiler.h"
#include "Runtime/Allocator/MemoryManager.h"
#include "Runtime/Allocator/MemoryMacros.h"

#if ENABLE_MEM_PROFILER

bool push_allocation_root(void* root, bool forcePush)
{
	return GetMemoryProfiler()?GetMemoryProfiler()->PushAllocationRoot(root, forcePush):false;
}

void  pop_allocation_root()
{
	GetMemoryProfiler()->PopAllocationRoot();
}

ProfilerAllocationHeader* get_current_allocation_root_header_internal()
{
	return GetMemoryProfiler()?GetMemoryProfiler()->GetCurrentRootHeader():NULL;
}

ProfilerAllocationHeader* get_allocation_header_internal(void* ptr, MemLabelRef label)
{
	BaseAllocator* alloc = GetMemoryManager().GetAllocator(label);
	return alloc->GetProfilerHeader(ptr);
}

void transfer_ownership_root_header(void* source, MemLabelRef label, ProfilerAllocationHeader* newRootHeader)
{
	if(GetMemoryManager().IsTempAllocatorLabel(label))
		return;
	GetMemoryProfiler()->TransferOwnership(source, GetMemoryManager().GetAllocator(label), newRootHeader);
}

void transfer_ownership(void* source, MemLabelRef label, const void* newroot)
{
	BaseAllocator* rootAlloc = GetMemoryManager().GetAllocatorContainingPtr(newroot);
	ProfilerAllocationHeader* rootHeader = rootAlloc->GetProfilerHeader(newroot);
	transfer_ownership_root_header(source, label, rootHeader);
}

void set_root_allocation(void* root, MemLabelRef label, const char* areaName, const char* objectName)
{
	pop_allocation_root();
	GetMemoryProfiler ()->RegisterRootAllocation (root, GetMemoryManager().GetAllocator(label), areaName, objectName);
}

void  assign_allocation_root(void* root, MemLabelRef label, const char* areaName, const char* objectName)
{
	GetMemoryProfiler ()->RegisterRootAllocation (root, GetMemoryManager().GetAllocator(label), areaName, objectName);
}

AllocationRootReference* get_root_reference_from_header(ProfilerAllocationHeader* root)
{
	return MemoryProfiler::GetRootReferenceFromHeader(root);
}

AllocationRootReference* copy_root_reference(AllocationRootReference* rootRef)
{
	if (rootRef)
		rootRef->Retain();
	return rootRef;
}

void release_root_reference(AllocationRootReference* rootRef)
{
	if (rootRef)
		rootRef->Release();
}

ProfilerAllocationHeader* get_root_header_from_reference(AllocationRootReference* rootref)
{
	return rootref? rootref->root: NULL;
}

#endif

void ValidateAllocatorIntegrity(MemLabelId label)
{
#if ENABLE_MEMORY_MANAGER
	GetMemoryManager().GetAllocator(label)->CheckIntegrity();
#endif
}