Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
LegacyNetBufferPool.cs
Go to the documentation of this file.
1using System;
3
4namespace Terraria.Net;
5
7{
8 private const int SMALL_BUFFER_SIZE = 256;
9
10 private const int MEDIUM_BUFFER_SIZE = 1024;
11
12 private const int LARGE_BUFFER_SIZE = 16384;
13
14 private static object bufferLock = new object();
15
17
19
21
22 private static int _smallBufferCount;
23
24 private static int _mediumBufferCount;
25
26 private static int _largeBufferCount;
27
28 private static int _customBufferCount;
29
30 public static byte[] RequestBuffer(int size)
31 {
33 {
34 if (size <= 256)
35 {
36 if (_smallBufferQueue.Count == 0)
37 {
39 return new byte[256];
40 }
41 return _smallBufferQueue.Dequeue();
42 }
43 if (size <= 1024)
44 {
45 if (_mediumBufferQueue.Count == 0)
46 {
48 return new byte[1024];
49 }
50 return _mediumBufferQueue.Dequeue();
51 }
52 if (size <= 16384)
53 {
54 if (_largeBufferQueue.Count == 0)
55 {
57 return new byte[16384];
58 }
59 return _largeBufferQueue.Dequeue();
60 }
62 return new byte[size];
63 }
64 }
65
66 public static byte[] RequestBuffer(byte[] data, int offset, int size)
67 {
68 byte[] array = RequestBuffer(size);
69 Buffer.BlockCopy(data, offset, array, 0, size);
70 return array;
71 }
72
73 public static void ReturnBuffer(byte[] buffer)
74 {
75 int num = buffer.Length;
77 {
78 if (num <= 256)
79 {
81 }
82 else if (num <= 1024)
83 {
85 }
86 else if (num <= 16384)
87 {
89 }
90 }
91 }
92
93 public static void DisplayBufferSizes()
94 {
96 {
97 Main.NewText("Small Buffers: " + _smallBufferQueue.Count + " queued of " + _smallBufferCount);
98 Main.NewText("Medium Buffers: " + _mediumBufferQueue.Count + " queued of " + _mediumBufferCount);
99 Main.NewText("Large Buffers: " + _largeBufferQueue.Count + " queued of " + _largeBufferCount);
100 Main.NewText("Custom Buffers: 0 queued of " + _customBufferCount);
101 }
102 }
103
104 public static void PrintBufferSizes()
105 {
107 {
108 Console.WriteLine("Small Buffers: " + _smallBufferQueue.Count + " queued of " + _smallBufferCount);
109 Console.WriteLine("Medium Buffers: " + _mediumBufferQueue.Count + " queued of " + _mediumBufferCount);
110 Console.WriteLine("Large Buffers: " + _largeBufferQueue.Count + " queued of " + _largeBufferCount);
111 Console.WriteLine("Custom Buffers: 0 queued of " + _customBufferCount);
112 Console.WriteLine("");
113 }
114 }
115}
static void BlockCopy(Array src, int srcOffset, Array dst, int dstOffset, int count)
Definition Buffer.cs:102
static void WriteLine()
Definition Console.cs:733
static void NewText(string newText, byte R=byte.MaxValue, byte G=byte.MaxValue, byte B=byte.MaxValue)
Definition Main.cs:61429
static Queue< byte[]> _mediumBufferQueue
static byte[] RequestBuffer(int size)
static void ReturnBuffer(byte[] buffer)
static Queue< byte[]> _smallBufferQueue
static Queue< byte[]> _largeBufferQueue
static byte[] RequestBuffer(byte[] data, int offset, int size)