diff options
| author | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
|---|---|---|
| committer | daoge_cmd <3523206925@qq.com> | 2026-03-01 12:16:08 +0800 |
| commit | b691c43c44ff180d10e7d4a9afc83b98551ff586 (patch) | |
| tree | 3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/ManualSample.cpp | |
| parent | def8cb415354ac390b7e89052a50605285f1aca9 (diff) | |
Initial commit
Diffstat (limited to 'Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/ManualSample.cpp')
| -rw-r--r-- | Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/ManualSample.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/ManualSample.cpp b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/ManualSample.cpp new file mode 100644 index 00000000..34914717 --- /dev/null +++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/Manual/ManualSample.cpp @@ -0,0 +1,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(); +} |
