Skip to content

Commit

Permalink
Fixed regression
Browse files Browse the repository at this point in the history
  • Loading branch information
sakno committed Jan 12, 2024
1 parent 40b6f54 commit 0d6f47f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/DotNext.Tests/Buffers/UnmanagedMemoryPoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static void SliceTest()
[Fact]
public static void Allocation()
{
using var manager = UnmanagedMemory.Allocate<long>(2);
using var manager = UnmanagedMemory.AllocateZeroed<long>(2);
Equal(2, manager.Length);

Equal(sizeof(long) * 2U, manager.Size);
Expand All @@ -130,7 +130,7 @@ public static void Allocation()
[Fact]
public static void Pooling()
{
using var pool = new UnmanagedMemoryPool<long>(10) { TrackAllocations = true };
using var pool = new UnmanagedMemoryPool<long>(10) { TrackAllocations = true, AllocateZeroedMemory = true };
using var manager = pool.Rent(2);
Equal(2, manager.Memory.Length);

Expand Down
6 changes: 5 additions & 1 deletion src/DotNext.Unsafe/Buffers/UnmanagedMemoryPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,16 @@ private void AddTracking(IUnmanagedMemory<T> owner)
public override IMemoryOwner<T> Rent(int length = -1)
{
ArgumentOutOfRangeException.ThrowIfGreaterThan(length, MaxBufferSize);
ArgumentOutOfRangeException.ThrowIfZero(length);

if (length < 0)
length = defaultBufferSize;

PoolingUnmanagedMemoryOwner<T> result;

unsafe
{
result = new PoolingUnmanagedMemoryOwner<T>(Math.Max(length, defaultBufferSize), allocator)
result = new PoolingUnmanagedMemoryOwner<T>(length, allocator)
{
OnDisposed = removeMemory,
};
Expand Down

0 comments on commit 0d6f47f

Please sign in to comment.