|
|
|
@ -12,8 +12,8 @@ namespace SixLabors.ImageSharp.Tests.Memory |
|
|
|
{ |
|
|
|
internal class TestMemoryAllocator : MemoryAllocator |
|
|
|
{ |
|
|
|
private readonly List<AllocationRequest> allocationLog = new List<AllocationRequest>(); |
|
|
|
private readonly List<ReturnRequest> returnLog = new List<ReturnRequest>(); |
|
|
|
private List<AllocationRequest> allocationLog; |
|
|
|
private List<ReturnRequest> returnLog; |
|
|
|
|
|
|
|
public TestMemoryAllocator(byte dirtyValue = 42) |
|
|
|
{ |
|
|
|
@ -27,12 +27,18 @@ namespace SixLabors.ImageSharp.Tests.Memory |
|
|
|
|
|
|
|
public int BufferCapacityInBytes { get; set; } = int.MaxValue; |
|
|
|
|
|
|
|
public IReadOnlyList<AllocationRequest> AllocationLog => this.allocationLog; |
|
|
|
public IReadOnlyList<AllocationRequest> AllocationLog => this.allocationLog ?? throw new InvalidOperationException("Call TestMemoryAllocator.EnableLogging() first!"); |
|
|
|
|
|
|
|
public IReadOnlyList<ReturnRequest> ReturnLog => this.returnLog; |
|
|
|
public IReadOnlyList<ReturnRequest> ReturnLog => this.returnLog ?? throw new InvalidOperationException("Call TestMemoryAllocator.EnableLogging() first!"); |
|
|
|
|
|
|
|
protected internal override int GetBufferCapacityInBytes() => this.BufferCapacityInBytes; |
|
|
|
|
|
|
|
public void EnableLogging() |
|
|
|
{ |
|
|
|
this.allocationLog = new List<AllocationRequest>(); |
|
|
|
this.returnLog = new List<ReturnRequest>(); |
|
|
|
} |
|
|
|
|
|
|
|
public override IMemoryOwner<T> Allocate<T>(int length, AllocationOptions options = AllocationOptions.None) |
|
|
|
{ |
|
|
|
T[] array = this.AllocateArray<T>(length, options); |
|
|
|
@ -43,7 +49,7 @@ namespace SixLabors.ImageSharp.Tests.Memory |
|
|
|
where T : struct |
|
|
|
{ |
|
|
|
var array = new T[length + 42]; |
|
|
|
this.allocationLog.Add(AllocationRequest.Create<T>(options, length, array)); |
|
|
|
this.allocationLog?.Add(AllocationRequest.Create<T>(options, length, array)); |
|
|
|
|
|
|
|
if (options == AllocationOptions.None) |
|
|
|
{ |
|
|
|
@ -57,7 +63,7 @@ namespace SixLabors.ImageSharp.Tests.Memory |
|
|
|
private void Return<T>(BasicArrayBuffer<T> buffer) |
|
|
|
where T : struct |
|
|
|
{ |
|
|
|
this.returnLog.Add(new ReturnRequest(buffer.Array.GetHashCode())); |
|
|
|
this.returnLog?.Add(new ReturnRequest(buffer.Array.GetHashCode())); |
|
|
|
} |
|
|
|
|
|
|
|
public struct AllocationRequest |
|
|
|
|