aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/ReplaceNewDeleteSample.cpp
diff options
context:
space:
mode:
authordaoge_cmd <3523206925@qq.com>2026-03-01 12:16:08 +0800
committerdaoge_cmd <3523206925@qq.com>2026-03-01 12:16:08 +0800
commitb691c43c44ff180d10e7d4a9afc83b98551ff586 (patch)
tree3e9849222cbc6ba49f2f1fc6e5fe7179632c7390 /Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/ReplaceNewDeleteSample.cpp
parentdef8cb415354ac390b7e89052a50605285f1aca9 (diff)
Initial commit
Diffstat (limited to 'Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/ReplaceNewDeleteSample.cpp')
-rw-r--r--Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/ReplaceNewDeleteSample.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/ReplaceNewDeleteSample.cpp b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/ReplaceNewDeleteSample.cpp
new file mode 100644
index 00000000..305d589b
--- /dev/null
+++ b/Minecraft.Client/PS3/PS3Extras/HeapInspector/Samples/ReplaceNewDelete/ReplaceNewDeleteSample.cpp
@@ -0,0 +1,67 @@
+// =================================================================================================================================
+// This sample demonstrates how to replace operator new and delete and how to send these allocations to the HeapInspector client.
+// Please note that the Hook sample captures allocations on a lower level and will also trace all new/delete allocations.
+//
+// WARNING: Make sure that you replace both the array and non-array operators. If there are any pairing issues in your code
+// (allocating with new[] and deleting with delete), HeapInspector will miss those deallocations and that will be problematic
+// for a subsequent allocation on that address: it will then warn that it found a double allocation. That will actually be a
+// sign that the operators aren't properly matched.
+// =================================================================================================================================
+
+#include "../../Server/HeapInspectorServer.h"
+#include <stdlib.h>
+#include <new>
+
+using namespace HeapInspectorServer;
+
+void Wait(int a_MilliSeconds);
+
+void* operator new(size_t a_Size)
+{
+ Mutation mutation = BeginAlloc();
+ void* mem = malloc(a_Size);
+ EndAlloc(mutation, 0, mem, a_Size, a_Size);
+ return mem;
+}
+
+void operator delete(void* a_Pointer)
+{
+ Mutation mutation = BeginFree();
+ free(a_Pointer);
+ EndFree(mutation, 0, a_Pointer);
+}
+
+void* operator new[](size_t a_Size)
+{
+ Mutation mutation = BeginAlloc();
+ void* mem = malloc(a_Size);
+ EndAlloc(mutation, 0, mem, a_Size, a_Size);
+ return mem;
+}
+
+void operator delete[](void* a_Pointer)
+{
+ Mutation mutation = BeginFree();
+ free(a_Pointer);
+ EndFree(mutation, 0, a_Pointer);
+}
+
+void RunHeapInspectorServer()
+{
+ Initialise(GetDefaultHeapInfo(), 3000, WaitForConnection_Enabled);
+
+ while (1)
+ {
+ int* xArray = new int[100];
+ float* y = new float;
+
+ Wait(100);
+
+ delete[] xArray;
+ delete y;
+
+ Wait(100);
+ }
+
+ Shutdown();
+}