Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
ArrayBuffer.cs
Go to the documentation of this file.
3
4namespace System.Net;
5
6[StructLayout(LayoutKind.Auto)]
7internal struct ArrayBuffer : IDisposable
8{
9 private readonly bool _usePool;
10
11 private byte[] _bytes;
12
13 private int _activeStart;
14
15 private int _availableStart;
16
18
20
22
23 public int AvailableLength => _bytes.Length - _availableStart;
24
26
28
29 public int Capacity => _bytes.Length;
30
31 public ArrayBuffer(int initialSize, bool usePool = false)
32 {
33 _usePool = usePool;
34 _bytes = (usePool ? ArrayPool<byte>.Shared.Rent(initialSize) : new byte[initialSize]);
35 _activeStart = 0;
37 }
38
39 public void Dispose()
40 {
41 _activeStart = 0;
43 byte[] bytes = _bytes;
44 _bytes = null;
45 if (_usePool && bytes != null)
46 {
48 }
49 }
50
55
56 public void Discard(int byteCount)
57 {
60 {
61 _activeStart = 0;
63 }
64 }
65
66 public void Commit(int byteCount)
67 {
69 }
70
72 {
74 {
75 return;
76 }
77 int num = _activeStart + AvailableLength;
78 if (byteCount <= num)
79 {
82 _activeStart = 0;
83 return;
84 }
85 int num2 = ActiveLength + byteCount;
86 int num3 = _bytes.Length;
87 do
88 {
89 num3 *= 2;
90 }
91 while (num3 < num2);
92 byte[] array = (_usePool ? ArrayPool<byte>.Shared.Rent(num3) : new byte[num3]);
93 byte[] bytes = _bytes;
94 if (ActiveLength != 0)
95 {
97 }
99 _activeStart = 0;
100 _bytes = array;
101 if (_usePool)
102 {
104 }
105 }
106
107 public void Grow()
108 {
110 }
111}
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Definition Buffer.cs:102
static ArrayPool< T > Shared
Definition ArrayPool.cs:7
ArrayBuffer(int initialSize, bool usePool=false)
Memory< byte > AvailableMemory
readonly bool _usePool
Definition ArrayBuffer.cs:9
Span< byte > ActiveSpan
Memory< byte > AvailableMemorySliced(int length)
void Commit(int byteCount)
void Discard(int byteCount)
void EnsureAvailableSpace(int byteCount)
Span< byte > AvailableSpan
Memory< byte > ActiveMemory