Make Helper calls threadsafe

This commit is contained in:
Garry Newman 2020-03-31 08:10:43 +01:00
parent 4c353264cb
commit ecdf217d08

View File

@ -9,8 +9,8 @@ internal static class Helpers
{
public const int MaxStringSize = 1024 * 32;
private static IntPtr[] MemoryPool;
private static int MemoryPoolIndex;
[ThreadStatic] private static IntPtr[] MemoryPool;
[ThreadStatic] private static int MemoryPoolIndex;
public static unsafe IntPtr TakeMemory()
{
@ -38,8 +38,8 @@ public static unsafe IntPtr TakeMemory()
}
private static byte[][] BufferPool;
private static int BufferPoolIndex;
[ThreadStatic] private static byte[][] BufferPool;
[ThreadStatic] private static int BufferPoolIndex;
/// <summary>
/// Returns a buffer. This will get returned and reused later on.
@ -49,9 +49,9 @@ public static byte[] TakeBuffer( int minSize )
if ( BufferPool == null )
{
//
// The pool has 8 items.
// The pool has 4 items.
//
BufferPool = new byte[8][];
BufferPool = new byte[4][];
for ( int i = 0; i < BufferPool.Length; i++ )
BufferPool[i] = new byte[ 1024 * 128 ];