Files
Performance-Fish/Source/PerformanceFish/Prepatching/FishStashHandle.cs
T
bbradson ca9321add8 Lots of new optimizations utilizing prepatcher
To start, this mod now requires Prepatcher and Fishery.
New optimizations include: gene ticking improvements, world object improvements, hediff optimizations, world pawn gc optimizations, better mothballing, dds support, ContentFinder caching, additions and changes to reflection caching, as well as various other additions. Multiplayer support has been improved too, but should be considered highly experimental. The WorkGiver_DoBill bug is fixed in this build. Multiple patches aiming to improve RimWorld's load time have been added too.
2023-06-03 20:24:38 +02:00

41 lines
1014 B
C#

// Copyright (c) 2023 bradson
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
using System.Runtime.InteropServices;
namespace PerformanceFish.Prepatching;
public class FishStashHandle : IDisposable
{
private static readonly List<nint> _allHandles = new();
public ref FishStash Stash => ref FishStash.FromHandle(Handle);
public nint Handle { get; }
public FishStashHandle(long handle)
{
if (_allHandles.Contains((nint)handle))
ThrowHelper.ThrowInvalidOperationException("Tried creating duplicate FishStashHandle.");
else
_allHandles.Add((nint)handle);
Handle = (nint)handle;
}
private void ReleaseUnmanagedResources()
{
Marshal.FreeHGlobal(Handle);
_allHandles.Remove(Handle);
}
public void Dispose()
{
ReleaseUnmanagedResources();
GC.SuppressFinalize(this);
}
~FishStashHandle() => ReleaseUnmanagedResources();
}