Skip to content

Commit

Permalink
test allocation limits
Browse files Browse the repository at this point in the history
  • Loading branch information
antonfirsov committed Apr 10, 2024
1 parent 3d298db commit cf9496d
Showing 1 changed file with 24 additions and 0 deletions.
Expand Up @@ -398,6 +398,30 @@ private static void AllocateSingleAndForget(UniformUnmanagedMemoryPoolMemoryAllo
}
}

[Fact]
public void Allocate_OverLimit_ThrowsInvalidMemoryOperationException()
{
MemoryAllocator allocator = MemoryAllocator.Create(new MemoryAllocatorOptions()
{
AllocationLimitMegabytes = 4
});
const int oneMb = 1 << 20;
allocator.Allocate<byte>(4 * oneMb).Dispose(); // Should work
Assert.Throws<InvalidMemoryOperationException>(() => allocator.Allocate<byte>(5 * oneMb));
}

[Fact]
public void AllocateGroup_OverLimit_ThrowsInvalidMemoryOperationException()
{
MemoryAllocator allocator = MemoryAllocator.Create(new MemoryAllocatorOptions()
{
AllocationLimitMegabytes = 4
});
const int oneMb = 1 << 20;
allocator.AllocateGroup<byte>(4 * oneMb, 1024).Dispose(); // Should work
Assert.Throws<InvalidMemoryOperationException>(() => allocator.AllocateGroup<byte>(5 * oneMb, 1024));
}

#if NETCOREAPP3_1_OR_GREATER
[Fact]
public void Issue2001_NegativeMemoryReportedByGc()
Expand Down

0 comments on commit cf9496d

Please sign in to comment.