Skip to content

Commit

Permalink
fix: Fixes STArray size and tests (#1737)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamronbatman committed Apr 23, 2024
1 parent 3a27ab8 commit 7a160bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 4 additions & 5 deletions Projects/Server.Tests/Tests/Buffers/STArrayPoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,11 @@ public void CachesOnlyUpToCPUCountPerBucket()
{
STArrayPool<byte>.Shared.ResetForTesting();

var cores = Environment.ProcessorCount;
var arrays1 = new byte[cores * 8 + 2][]; // 1 for the cache, and 8 * CPU for the stacks
var weakReferences1 = new WeakReference[cores * 8 + 2];
var arrays1 = new byte[32 + 2][]; // 1 for the cache, 32 for the cores, and 1 for overflow
var weakReferences1 = new WeakReference[32 + 2];

var arrays2 = new byte[cores * 8 + 2][]; // 1 for the cache, and 8 * CPU for the stacks
var weakReferences2 = new WeakReference[cores * 8 + 2];
var arrays2 = new byte[32 + 2][];
var weakReferences2 = new WeakReference[32 + 2];

for (var i = 0; i < arrays1.Length; i++)
{
Expand Down
6 changes: 3 additions & 3 deletions Projects/Server/Buffers/STArrayPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public override T[] Rent(int minimumLength)
if (minimumLength == 0)
{
// We aren't renting.
return Array.Empty<T>();
return [];
}

if (minimumLength < 0)
Expand All @@ -74,7 +74,7 @@ public override T[] Rent(int minimumLength)
return buffer;
}

public override void Return(T[] array, bool clearArray = false)
public override void Return(T[]? array, bool clearArray = false)
{
if (array is null)
{
Expand Down Expand Up @@ -231,7 +231,7 @@ internal static MemoryPressure GetMemoryPressure()
private sealed class STArrayStack
{
// Maximum buffers we will store in our stack
private readonly T[][] _arrays = new T[StackArraySize * Environment.ProcessorCount][];
private readonly T[][] _arrays = new T[StackArraySize][];
private int _count;
private long _ticks;

Expand Down

0 comments on commit 7a160bb

Please sign in to comment.