aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/ManualSample.cpp
blob: 34914717eeb5021ef6b39090b2783cc7dd0c9b2a (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
// =================================================================================================================================
// This sample demonstrates how to use the Server API to send allocs, reallocs and frees directly to the client. It also shows 
// how to configure multiple heaps.
// =================================================================================================================================

#include "../../Server/HeapInspectorServer.h"
#include <stdlib.h>

using namespace HeapInspectorServer;

void Wait(int a_MilliSeconds);

std::vector<HeapInfo> GetHeapInfo()
{
	std::vector<HeapInfo> result;
	HeapInfo heapInfo;
	heapInfo.m_Description = "Heap1";
	heapInfo.m_Range.m_Min = 0;
	heapInfo.m_Range.m_Max = 0x80000000 - 1;
	result.push_back(heapInfo);

	heapInfo.m_Description = "Heap2";
	heapInfo.m_Range.m_Min = 0;
	heapInfo.m_Range.m_Max = 0x80000000 - 1;
	result.push_back(heapInfo);

	return result;
}

void* Alloc(uint32 a_Size, int a_Heap)
{
	Mutation mutation = BeginAlloc();
	void* mem = malloc(a_Size);
	EndAlloc(mutation, a_Heap, mem, a_Size, a_Size);
	return mem;
}

void Free(void* a_Block, int a_Heap)
{
	Mutation mutation = BeginFree();
	free(a_Block);
	EndFree(mutation, a_Heap, a_Block);
}

void* ReAlloc(void* a_OldBlock, uint32 a_Size, int a_Heap)
{
	Mutation mutation = BeginReAlloc();
	void* mem = realloc(a_OldBlock, a_Size);
	EndReAlloc(mutation, a_Heap, a_OldBlock, mem, a_Size, a_Size);
	return mem;
}

void RunHeapInspectorServer()
{
	Initialise(GetHeapInfo(), 3000, WaitForConnection_Enabled);

	while (1)
	{
		void* mem1;
		void* memB;
		
		mem1 = Alloc(16, 0);
		memB = Alloc(1024, 1);

		Wait(100);

		void* mem2 = ReAlloc(mem1, 32, 0);

		Wait(100);

		Free(mem2, 0);
		Free(memB, 1);

		Wait(100);
	}

	Shutdown();
}