From 3cfc9d91fcf70aee2e692491e3965d47e8db3393 Mon Sep 17 00:00:00 2001 From: Vladimir Sadov Date: Tue, 28 May 2019 14:28:56 -0700 Subject: [PATCH] Using AllocateUninitializedArray in array pool (dotnet/coreclr#24504) * Just use `new T[]` when elements are not pointer-free * reduce zeroing out when not necessary. * use AllocateUninitializedArray in ArrayPool Signed-off-by: dotnet-bot --- .../shared/System/Buffers/ConfigurableArrayPool.cs | 6 +++--- .../System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Buffers/ConfigurableArrayPool.cs b/src/System.Private.CoreLib/shared/System/Buffers/ConfigurableArrayPool.cs index 6dd30632581..054a38fc602 100644 --- a/src/System.Private.CoreLib/shared/System/Buffers/ConfigurableArrayPool.cs +++ b/src/System.Private.CoreLib/shared/System/Buffers/ConfigurableArrayPool.cs @@ -100,13 +100,13 @@ public override T[] Rent(int minimumLength) // The pool was exhausted for this buffer size. Allocate a new buffer with a size corresponding // to the appropriate bucket. - buffer = new T[_buckets[index]._bufferLength]; + buffer = GC.AllocateUninitializedArray(_buckets[index]._bufferLength); } else { // The request was for a size too large for the pool. Allocate an array of exactly the requested length. // When it's returned to the pool, we'll simply throw it away. - buffer = new T[minimumLength]; + buffer = GC.AllocateUninitializedArray(minimumLength); } if (log.IsEnabled()) @@ -215,7 +215,7 @@ internal Bucket(int bufferLength, int numberOfBuffers, int poolId) // for that slot, in which case we should do so now. if (allocateBuffer) { - buffer = new T[_bufferLength]; + buffer = GC.AllocateUninitializedArray(_bufferLength); var log = ArrayPoolEventSource.Log; if (log.IsEnabled()) diff --git a/src/System.Private.CoreLib/shared/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs b/src/System.Private.CoreLib/shared/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs index 47470715ecf..7369ed8ca6f 100644 --- a/src/System.Private.CoreLib/shared/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs +++ b/src/System.Private.CoreLib/shared/System/Buffers/TlsOverPerCoreLockedStacksArrayPool.cs @@ -136,13 +136,13 @@ public override T[] Rent(int minimumLength) } // No buffer available. Allocate a new buffer with a size corresponding to the appropriate bucket. - buffer = new T[_bucketArraySizes[bucketIndex]]; + buffer = GC.AllocateUninitializedArray(_bucketArraySizes[bucketIndex]); } else { // The request was for a size too large for the pool. Allocate an array of exactly the requested length. // When it's returned to the pool, we'll simply throw it away. - buffer = new T[minimumLength]; + buffer = GC.AllocateUninitializedArray(minimumLength); } if (log.IsEnabled())