From 7a160bb0fd9d51f5b4963809552e5b89e9440f54 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Tue, 23 Apr 2024 16:18:24 -0700 Subject: [PATCH] fix: Fixes STArray size and tests (#1737) --- Projects/Server.Tests/Tests/Buffers/STArrayPoolTests.cs | 9 ++++----- Projects/Server/Buffers/STArrayPool.cs | 6 +++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/Projects/Server.Tests/Tests/Buffers/STArrayPoolTests.cs b/Projects/Server.Tests/Tests/Buffers/STArrayPoolTests.cs index 0b7ee8937..3a51999c0 100644 --- a/Projects/Server.Tests/Tests/Buffers/STArrayPoolTests.cs +++ b/Projects/Server.Tests/Tests/Buffers/STArrayPoolTests.cs @@ -36,12 +36,11 @@ public class STArrayPoolTests { STArrayPool.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++) { diff --git a/Projects/Server/Buffers/STArrayPool.cs b/Projects/Server/Buffers/STArrayPool.cs index 311c40a72..d53d650ee 100644 --- a/Projects/Server/Buffers/STArrayPool.cs +++ b/Projects/Server/Buffers/STArrayPool.cs @@ -62,7 +62,7 @@ public class STArrayPool : ArrayPool if (minimumLength == 0) { // We aren't renting. - return Array.Empty(); + return []; } if (minimumLength < 0) @@ -74,7 +74,7 @@ public class STArrayPool : ArrayPool return buffer; } - public override void Return(T[] array, bool clearArray = false) + public override void Return(T[]? array, bool clearArray = false) { if (array is null) { @@ -231,7 +231,7 @@ public class STArrayPool : ArrayPool 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;