public static void Init() { if (m_bUseBytePool) { m_BytePool = ArrayPool <byte> .Create(8 * 1024, 50); } else { m_BytePool = ArrayPool <byte> .System(); } }
public KCPServer(int port) { m_port = port; if (UdpLibConfig.UseBytePool) { BytePool = ArrayPool <byte> .Create(8 * 1024, 50); } else { BytePool = ArrayPool <byte> .System(); } }
public KCPServer(string host, UInt16 port) { m_host = host; m_port = port; if (UdpLibConfig.UseBytePool) { BytePool = ArrayPool <byte> .Create(8 * 1024, 50); } else { BytePool = ArrayPool <byte> .System(); } KCPLib.BufferAlloc = (size) => { return(BytePool.Rent(size)); }; KCPLib.BufferFree = (buf) => { BytePool.Return(buf); }; }
private static void InitBytePool() { if (BytePool == null) { if (UdpLibConfig.UseBytePool) { BytePool = ArrayPool <byte> .Create(8 * 1024, 50); } else { BytePool = ArrayPool <byte> .System(); } KCPLib.BufferAlloc = (size) => { return(BytePool.Rent(size)); }; KCPLib.BufferFree = (buf) => { BytePool.Return(buf); }; } }
static void Main(string[] args) { Console.WriteLine("输入ip"); string host = Console.ReadLine(); if (host == "") { host = "127.0.0.1"; } Console.WriteLine("输入起始用户ID:"); int id = int.Parse(Console.ReadLine()); Console.WriteLine("输入客户端数量"); int c = 300; string s = Console.ReadLine(); if (s != "") { c = int.Parse(s); } Console.WriteLine("开始---"); IRQLog.AppLog = new IRQLog(); IRQLog.AppLog.Start("output.csv"); UdpLibConfig.HandshakeDelay = 2000; UdpLibConfig.HandshakeRetry = 10; //客户端,没必要启用内存池 //如果需要启用,则ByteArrayPool.cs中的条件编译“SERVERSIDE"需启用 UdpLibConfig.UseBytePool = false; ArrayPool <byte> BytePool; if (UdpLibConfig.UseBytePool) { BytePool = ArrayPool <byte> .Create(8 * 1024, 50); } else { BytePool = ArrayPool <byte> .System(); } KCPLib.BufferAlloc = (size) => { return(BytePool.Rent(size)); }; KCPLib.BufferFree = (buf) => { BytePool.Return(buf); }; List <ClientState> ls = new List <ClientState>(); for (int i = id; i <= c + id; i++) { Thread thd = new Thread((_) => { ClientState cs = new ClientState(); cs.Start(host, 10001, (uint)((int)_), (int)_); }); thd.Start(i); } Stopwatch sw = Stopwatch.StartNew(); while (true) { Console.WriteLine(ClientState.m_total / sw.Elapsed.TotalSeconds); System.Threading.Thread.Sleep(2000); } Console.ReadLine(); }