Merge pull request #136 from rreminy/patch-6

Remove constant Alloc and Free calls from ActorTable
This commit is contained in:
goaaats 2020-07-16 23:32:10 +02:00 committed by GitHub
commit e1936a217c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,6 +32,9 @@ namespace Dalamud.Game.ClientState.Actors {
private ClientStateAddressResolver Address { get; } private ClientStateAddressResolver Address { get; }
private Dalamud dalamud; private Dalamud dalamud;
private static int sz = Marshal.SizeOf(typeof(Structs.Actor));
private IntPtr actorMem = Marshal.AllocHGlobal(sz);
/// <summary> /// <summary>
/// Set up the actor table collection. /// Set up the actor table collection.
/// </summary> /// </summary>
@ -64,15 +67,15 @@ namespace Dalamud.Game.ClientState.Actors {
return null; return null;
// FIXME: hack workaround for trying to access the player on logout, after the main object has been deleted // 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 sz = Marshal.SizeOf(typeof(Structs.Actor));
var actorMem = Marshal.AllocHGlobal(sz); // we arguably could just reuse this //var actorMem = Marshal.AllocHGlobal(sz); // we arguably could just reuse this
if (!ReadProcessMemory(Process.GetCurrentProcess().Handle, offset, actorMem, sz, out _)) { if (!ReadProcessMemory(Process.GetCurrentProcess().Handle, offset, actorMem, sz, out _)) {
Log.Debug("ActorTable - ReadProcessMemory failed: likely player deletion during logout"); Log.Debug("ActorTable - ReadProcessMemory failed: likely player deletion during logout");
return null; return null;
} }
var actorStruct = Marshal.PtrToStructure<Structs.Actor>(actorMem); var actorStruct = Marshal.PtrToStructure<Structs.Actor>(actorMem);
Marshal.FreeHGlobal(actorMem); //Marshal.FreeHGlobal(actorMem);
//Log.Debug("ActorTable[{0}]: {1} - {2} - {3}", index, tblIndex.ToString("X"), offset.ToString("X"), //Log.Debug("ActorTable[{0}]: {1} - {2} - {3}", index, tblIndex.ToString("X"), offset.ToString("X"),
// actorStruct.ObjectKind.ToString()); // actorStruct.ObjectKind.ToString());