2023-01-17 05:13:24 +01:00
|
|
|
using Ryujinx.Memory;
|
|
|
|
using System;
|
|
|
|
|
|
|
|
namespace Ryujinx.Cpu
|
|
|
|
{
|
2023-07-01 04:18:52 +02:00
|
|
|
readonly struct PrivateMemoryAllocation : IDisposable
|
2023-01-17 05:13:24 +01:00
|
|
|
{
|
|
|
|
private readonly PrivateMemoryAllocator _owner;
|
|
|
|
private readonly PrivateMemoryAllocator.Block _block;
|
|
|
|
|
|
|
|
public bool IsValid => _owner != null;
|
|
|
|
public MemoryBlock Memory => _block?.Memory;
|
|
|
|
public ulong Offset { get; }
|
|
|
|
public ulong Size { get; }
|
|
|
|
|
|
|
|
public PrivateMemoryAllocation(
|
|
|
|
PrivateMemoryAllocator owner,
|
|
|
|
PrivateMemoryAllocator.Block block,
|
|
|
|
ulong offset,
|
|
|
|
ulong size)
|
|
|
|
{
|
|
|
|
_owner = owner;
|
|
|
|
_block = block;
|
|
|
|
Offset = offset;
|
|
|
|
Size = size;
|
|
|
|
}
|
|
|
|
|
|
|
|
public (PrivateMemoryAllocation, PrivateMemoryAllocation) Split(ulong splitOffset)
|
|
|
|
{
|
2023-07-01 04:18:52 +02:00
|
|
|
PrivateMemoryAllocation left = new(_owner, _block, Offset, splitOffset);
|
|
|
|
PrivateMemoryAllocation right = new(_owner, _block, Offset + splitOffset, Size - splitOffset);
|
2023-01-17 05:13:24 +01:00
|
|
|
|
|
|
|
return (left, right);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Dispose()
|
|
|
|
{
|
|
|
|
_owner.Free(_block, Offset, Size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|