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

◆ Trim()

Definition at line 311 of file TlsOverPerCoreLockedStacksArrayPool.cs.

312 {
313 int tickCount = Environment.TickCount;
314 Utilities.MemoryPressure memoryPressure = Utilities.GetMemoryPressure();
315 ArrayPoolEventSource log = ArrayPoolEventSource.Log;
316 if (log.IsEnabled())
317 {
318 log.BufferTrimPoll(tickCount, (int)memoryPressure);
319 }
320 PerCoreLockedStacks[] buckets = _buckets;
321 for (int i = 0; i < buckets.Length; i++)
322 {
323 buckets[i]?.Trim(tickCount, Id, memoryPressure, Utilities.GetMaxSizeForBucket(i));
324 }
325 if (memoryPressure == Utilities.MemoryPressure.High)
326 {
327 if (log.IsEnabled())
328 {
329 foreach (KeyValuePair<ThreadLocalArray[], object> item in (IEnumerable<KeyValuePair<ThreadLocalArray[], object>>)_allTlsBuckets)
330 {
331 ThreadLocalArray[] key = item.Key;
332 for (int j = 0; j < key.Length; j++)
333 {
334 T[] array = Interlocked.Exchange(ref key[j].Array, null);
335 if (array != null)
336 {
337 log.BufferTrimmed(array.GetHashCode(), array.Length, Id);
338 }
339 }
340 }
341 }
342 else
343 {
344 foreach (KeyValuePair<ThreadLocalArray[], object> item2 in (IEnumerable<KeyValuePair<ThreadLocalArray[], object>>)_allTlsBuckets)
345 {
346 Array.Clear(item2.Key);
347 }
348 }
349 }
350 else
351 {
352 uint num = ((memoryPressure != Utilities.MemoryPressure.Medium) ? 30000u : 15000u);
353 uint num2 = num;
354 foreach (KeyValuePair<ThreadLocalArray[], object> item3 in (IEnumerable<KeyValuePair<ThreadLocalArray[], object>>)_allTlsBuckets)
355 {
356 ThreadLocalArray[] key2 = item3.Key;
357 for (int k = 0; k < key2.Length; k++)
358 {
359 if (key2[k].Array == null)
360 {
361 continue;
362 }
363 int millisecondsTimeStamp = key2[k].MillisecondsTimeStamp;
364 if (millisecondsTimeStamp == 0)
365 {
366 key2[k].MillisecondsTimeStamp = tickCount;
367 }
368 else if (tickCount - millisecondsTimeStamp >= num2)
369 {
370 T[] array2 = Interlocked.Exchange(ref key2[k].Array, null);
371 if (array2 != null && log.IsEnabled())
372 {
373 log.BufferTrimmed(array2.GetHashCode(), array2.Length, Id);
374 }
375 }
376 }
377 }
378 }
379 return true;
380 }
void Trim(int currentMilliseconds, int id, Utilities.MemoryPressure pressure, int bucketSize)
readonly ConditionalWeakTable< ThreadLocalArray[], object > _allTlsBuckets
static int Exchange(ref int location1, int value)

References System.Buffers.TlsOverPerCoreLockedStacksArrayPool< T >._allTlsBuckets, System.Buffers.TlsOverPerCoreLockedStacksArrayPool< T >._buckets, System.array, System.Array.Clear(), System.Threading.Interlocked.Exchange(), System.Buffers.Utilities.GetMaxSizeForBucket(), System.Buffers.Utilities.GetMemoryPressure(), System.Buffers.TlsOverPerCoreLockedStacksArrayPool< T >.Id, System.item, System.key, System.Buffers.ArrayPoolEventSource.Log, System.Environment.TickCount, and System.Buffers.TlsOverPerCoreLockedStacksArrayPool< T >.PerCoreLockedStacks.Trim().