Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Rent()

override T[] System.Buffers.TlsOverPerCoreLockedStacksArrayPool< T >.Rent ( int minimumLength)
inline

Definition at line 212 of file TlsOverPerCoreLockedStacksArrayPool.cs.

213 {
214 ArrayPoolEventSource log = ArrayPoolEventSource.Log;
215 int num = Utilities.SelectBucketIndex(minimumLength);
216 ThreadLocalArray[] array = t_tlsBuckets;
217 T[] array2;
218 if (array != null && (uint)num < (uint)array.Length)
219 {
220 array2 = array[num].Array;
221 if (array2 != null)
222 {
223 array[num].Array = null;
224 if (log.IsEnabled())
225 {
226 log.BufferRented(array2.GetHashCode(), array2.Length, Id, num);
227 }
228 return array2;
229 }
230 }
231 PerCoreLockedStacks[] buckets = _buckets;
232 if ((uint)num < (uint)buckets.Length)
233 {
234 PerCoreLockedStacks perCoreLockedStacks = buckets[num];
235 if (perCoreLockedStacks != null)
236 {
237 array2 = perCoreLockedStacks.TryPop();
238 if (array2 != null)
239 {
240 if (log.IsEnabled())
241 {
242 log.BufferRented(array2.GetHashCode(), array2.Length, Id, num);
243 }
244 return array2;
245 }
246 }
247 minimumLength = Utilities.GetMaxSizeForBucket(num);
248 }
249 else
250 {
251 if (minimumLength == 0)
252 {
253 return Array.Empty<T>();
254 }
255 if (minimumLength < 0)
256 {
257 throw new ArgumentOutOfRangeException("minimumLength");
258 }
259 }
260 array2 = GC.AllocateUninitializedArray<T>(minimumLength);
261 if (log.IsEnabled())
262 {
263 int hashCode = array2.GetHashCode();
264 log.BufferRented(hashCode, array2.Length, Id, -1);
265 log.BufferAllocated(hashCode, array2.Length, Id, -1, (num >= _buckets.Length) ? ArrayPoolEventSource.BufferAllocatedReason.OverMaximumSize : ArrayPoolEventSource.BufferAllocatedReason.PoolExhausted);
266 }
267 return array2;
268 }

References System.Buffers.TlsOverPerCoreLockedStacksArrayPool< T >._buckets, System.array, System.Buffers.Utilities.GetMaxSizeForBucket(), System.Buffers.TlsOverPerCoreLockedStacksArrayPool< T >.Id, System.Buffers.ArrayPoolEventSource.Log, System.Buffers.Utilities.SelectBucketIndex(), and System.Buffers.TlsOverPerCoreLockedStacksArrayPool< T >.t_tlsBuckets.