// // ManagedMemoryAllocation.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Net.NetworkInformation; using Reloaded.Memory.Sources; namespace NosSmooth.Injector; /// /// Represents freeable memory allocation. /// internal class ManagedMemoryAllocation : IDisposable { private readonly IMemory _memory; /// /// Initializes a new instance of the class. /// /// The memory with allocation. /// The pointer to allocated memory. public ManagedMemoryAllocation(IMemory memory, nuint pointer) { Pointer = pointer; _memory = memory; } /// /// The allocated pointer number. /// public nuint Pointer { get; private set; } /// /// Whether the memory is currently allocated. /// public bool Allocated => Pointer != nuint.Zero; /// public void Dispose() { _memory.Free(Pointer); Pointer = nuint.Zero; } }