提交 e421481e 编写于 作者: V Vladimir Sadov 提交者: Stephen Toub

Do not use `AllocateUninitializedArray` in private array pools. (dotnet/coreclr#26338)

User may have extra expectations for the privatly owned array pools.
For example there could be an expectation that array never contains negative numbers (since user never puts them there). Uninitialized allocations can break such expectations.

Commit migrated from https://github.com/dotnet/coreclr/commit/c89fd6f88744bfee034e792906700c5a17e1b953
上级 2c8e1fff
......@@ -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 = GC.AllocateUninitializedArray<T>(_buckets[index]._bufferLength);
buffer = new 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 = GC.AllocateUninitializedArray<T>(minimumLength);
buffer = new T[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 = GC.AllocateUninitializedArray<T>(_bufferLength);
buffer = new T[_bufferLength];
ArrayPoolEventSource log = ArrayPoolEventSource.Log;
if (log.IsEnabled())
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册