From 9e85dcb00d17bebbc58672f057b70e57365d4991 Mon Sep 17 00:00:00 2001 From: AzureGem Date: Fri, 10 Jul 2020 11:58:26 -0400 Subject: [PATCH] Remove constant Alloc and Free calls from ActorTable Remove the constant allocations and freeing of the actor memory from the actor table's array function --- Dalamud/Game/ClientState/Actors/ActorTable.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Dalamud/Game/ClientState/Actors/ActorTable.cs b/Dalamud/Game/ClientState/Actors/ActorTable.cs index b21f5c4fb..e6e02068d 100644 --- a/Dalamud/Game/ClientState/Actors/ActorTable.cs +++ b/Dalamud/Game/ClientState/Actors/ActorTable.cs @@ -32,6 +32,9 @@ namespace Dalamud.Game.ClientState.Actors { private ClientStateAddressResolver Address { get; } private Dalamud dalamud; + private static int sz = Marshal.SizeOf(typeof(Structs.Actor)); + private IntPtr actorMem = Marshal.AllocHGlobal(sz); + /// /// Set up the actor table collection. /// @@ -64,15 +67,15 @@ namespace Dalamud.Game.ClientState.Actors { return null; // FIXME: hack workaround for trying to access the player on logout, after the main object has been deleted - var sz = Marshal.SizeOf(typeof(Structs.Actor)); - var actorMem = Marshal.AllocHGlobal(sz); // we arguably could just reuse this + //var sz = Marshal.SizeOf(typeof(Structs.Actor)); + //var actorMem = Marshal.AllocHGlobal(sz); // we arguably could just reuse this if (!ReadProcessMemory(Process.GetCurrentProcess().Handle, offset, actorMem, sz, out _)) { Log.Debug("ActorTable - ReadProcessMemory failed: likely player deletion during logout"); return null; } var actorStruct = Marshal.PtrToStructure(actorMem); - Marshal.FreeHGlobal(actorMem); + //Marshal.FreeHGlobal(actorMem); //Log.Debug("ActorTable[{0}]: {1} - {2} - {3}", index, tblIndex.ToString("X"), offset.ToString("X"), // actorStruct.ObjectKind.ToString());