/ src / Ryujinx.Cpu / PrivateMemoryAllocation.cs
PrivateMemoryAllocation.cs
 1  using Ryujinx.Memory;
 2  using System;
 3  
 4  namespace Ryujinx.Cpu
 5  {
 6      readonly struct PrivateMemoryAllocation : IDisposable
 7      {
 8          private readonly PrivateMemoryAllocator _owner;
 9          private readonly PrivateMemoryAllocator.Block _block;
10  
11          public bool IsValid => _owner != null;
12          public MemoryBlock Memory => _block?.Memory;
13          public ulong Offset { get; }
14          public ulong Size { get; }
15  
16          public PrivateMemoryAllocation(
17              PrivateMemoryAllocator owner,
18              PrivateMemoryAllocator.Block block,
19              ulong offset,
20              ulong size)
21          {
22              _owner = owner;
23              _block = block;
24              Offset = offset;
25              Size = size;
26          }
27  
28          public (PrivateMemoryAllocation, PrivateMemoryAllocation) Split(ulong splitOffset)
29          {
30              PrivateMemoryAllocation left = new(_owner, _block, Offset, splitOffset);
31              PrivateMemoryAllocation right = new(_owner, _block, Offset + splitOffset, Size - splitOffset);
32  
33              return (left, right);
34          }
35  
36          public void Dispose()
37          {
38              _owner.Free(_block, Offset, Size);
39          }
40      }
41  }