From 2695c6cece1c509a0eb4c6f5c6063bea1d04f917 Mon Sep 17 00:00:00 2001 From: binjian <1101811211@qq.com> Date: Mon, 13 May 2024 18:43:13 +0800 Subject: [PATCH] Fix CappedArrayPool : 1. alloc new array without caching 2. some cached array is not be used --- .../VContainer/Runtime/Internal/CappedArrayPool.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/VContainer/Assets/VContainer/Runtime/Internal/CappedArrayPool.cs b/VContainer/Assets/VContainer/Runtime/Internal/CappedArrayPool.cs index 13d7d56d..dbdb4b14 100644 --- a/VContainer/Assets/VContainer/Runtime/Internal/CappedArrayPool.cs +++ b/VContainer/Assets/VContainer/Runtime/Internal/CappedArrayPool.cs @@ -24,7 +24,7 @@ internal CappedArrayPool(int maxLength) { buckets[i][j] = new T[arrayLength]; } - tails[i] = buckets[i].Length - 1; + tails[i] = 0; } } @@ -48,7 +48,12 @@ public T[] Rent(int length) buckets[i] = bucket; } - var result = bucket[tail] ?? new T[length]; + if (bucket[tail] == null) + { + bucket[tail] = new T[length]; + } + + var result = bucket[tail]; tails[i] += 1; return result; }