Skip to content

Commit 11a90dd

Browse files
committed
Fixed buffer allocation size
1 parent 276a0a1 commit 11a90dd

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/DotNext.IO/IO/FileReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private ref readonly MemoryOwner<byte> EnsureBufferAllocated()
103103
{
104104
ref var result = ref buffer;
105105
if (result.IsEmpty)
106-
result = Allocator.AllocateAtLeast(maxBufferSize);
106+
result = Allocator.AllocateExactly(maxBufferSize);
107107

108108
Debug.Assert(!result.IsEmpty);
109109
return ref result;

src/DotNext.IO/IO/FileWriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private ref readonly MemoryOwner<byte> EnsureBufferAllocated()
7171
{
7272
ref var result = ref buffer;
7373
if (result.IsEmpty)
74-
result = Allocator.AllocateAtLeast(maxBufferSize);
74+
result = Allocator.AllocateExactly(maxBufferSize);
7575

7676
Debug.Assert(!result.IsEmpty);
7777
return ref result;
@@ -108,7 +108,7 @@ public void Produce(int count)
108108
ArgumentOutOfRangeException.ThrowIfGreaterThan((uint)count, (uint)FreeCapacity, nameof(count));
109109

110110
if (count > 0 && buffer.IsEmpty)
111-
buffer = Allocator.AllocateAtLeast(maxBufferSize);
111+
buffer = Allocator.AllocateExactly(maxBufferSize);
112112

113113
bufferOffset += count;
114114
}

0 commit comments

Comments
 (0)