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
27 public ArrayBuffer(int initialSize, bool usePool = false)
28 {
29 _usePool = usePool;
30 _bytes = (usePool ? ArrayPool<byte>.Shared.Rent(initialSize) : new byte[initialSize]);
31 _activeStart = 0;
33 }
34
35 public void Dispose()
36 {
37 _activeStart = 0;
39 byte[] bytes = _bytes;
40 _bytes = null;
41 if (_usePool && bytes != null)
42 {
44 }
45 }
46
47 public void Discard(int byteCount)
48 {
51 {
52 _activeStart = 0;
54 }
55 }
56
57 public void Commit(int byteCount)
58 {
60 }
61
63 {
65 {
66 return;
67 }
68 int num = _activeStart + AvailableLength;
69 if (byteCount <= num)
70 {
73 _activeStart = 0;
74 return;
75 }
76 int num2 = ActiveLength + byteCount;
77 int num3 = _bytes.Length;
78 do
79 {
80 num3 *= 2;
81 }
82 while (num3 < num2);
83 byte[] array = (_usePool ? ArrayPool<byte>.Shared.Rent(num3) : new byte[num3]);
84 byte[] bytes = _bytes;
85 if (ActiveLength != 0)
86 {
88 }
90 _activeStart = 0;
91 _bytes = array;
92 if (_usePool)
93 {
95 }
96 }
97}
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
ReadOnlySpan< byte > ActiveReadOnlySpan
void Commit(int byteCount)
void Discard(int byteCount)
void EnsureAvailableSpace(int byteCount)