Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ArrayMemoryPool.cs
Go to the documentation of this file.
2
3namespace System.Buffers;
4
5internal sealed class ArrayMemoryPool<T> : MemoryPool<T>
6{
8 {
9 private T[] _array;
10
12 {
13 get
14 {
15 T[] array = _array;
16 if (array == null)
17 {
19 }
20 return new Memory<T>(array);
21 }
22 }
23
24 public ArrayMemoryPoolBuffer(int size)
25 {
26 _array = ArrayPool<T>.Shared.Rent(size);
27 }
28
29 public void Dispose()
30 {
31 T[] array = _array;
32 if (array != null)
33 {
34 _array = null;
36 }
37 }
38 }
39
40 public sealed override int MaxBufferSize => int.MaxValue;
41
42 public sealed override IMemoryOwner<T> Rent(int minimumBufferSize = -1)
43 {
44 if (minimumBufferSize == -1)
45 {
46 minimumBufferSize = 1 + 4095 / Unsafe.SizeOf<T>();
47 }
48 else if ((uint)minimumBufferSize > 2147483647u)
49 {
50 System.ThrowHelper.ThrowArgumentOutOfRangeException(System.ExceptionArgument.minimumBufferSize);
51 }
53 }
54
55 protected sealed override void Dispose(bool disposing)
56 {
57 }
58}
override void Dispose(bool disposing)
override IMemoryOwner< T > Rent(int minimumBufferSize=-1)
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
static void ThrowArgumentOutOfRangeException(System.ExceptionArgument argument)
static void ThrowObjectDisposedException_ArrayMemoryPoolBuffer()