PrivateMemoryAllocation.cs 1.2 KB

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