Skip to content

Commit

Permalink
Using AllocateUninitializedArray in array pool (dotnet/coreclr#24504)
Browse files Browse the repository at this point in the history
* 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 <dotnet-bot@microsoft.com>
  • Loading branch information
VSadov authored and dotnet-bot committed May 29, 2019
1 parent 05e0578 commit 3cfc9d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(_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<T>(minimumLength);
}

if (log.IsEnabled())
Expand Down Expand Up @@ -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<T>(_bufferLength);

var log = ArrayPoolEventSource.Log;
if (log.IsEnabled())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>(_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<T>(minimumLength);
}

if (log.IsEnabled())
Expand Down

0 comments on commit 3cfc9d9

Please sign in to comment.