Ejemplo n.º 1
0
 static void Reset()
 {
     BytePools[BytePools.Length - 1] = new BytePool(int.MaxValue);
     for (int i = 0; i < BytePools.Length - 1; i++)
     {
         BytePools[i] = new BytePool((int)Math.Pow(2, i + 10));
     }
 }
Ejemplo n.º 2
0
            public static void ResetPool(ITracer tracer, uint indexEntryCount)
            {
                stringPool = new ObjectPool <LazyUTF8String>(tracer, Convert.ToInt32(indexEntryCount * PoolAllocationMultipliers.StringPool), objectCreator: () => new LazyUTF8String());
                if (bytePool != null)
                {
                    bytePool.UnpinPool();
                }

                bytePool = new BytePool(tracer, indexEntryCount);
            }
            public static void ResetPool()
            {
                stringPool = new ObjectPool <LazyUTF8String>(StringAllocationSize, objectCreator: () => new LazyUTF8String());
                if (bytePool != null)
                {
                    bytePool.UnpinPool();
                }

                bytePool = new BytePool();
            }
Ejemplo n.º 4
0
            public static void InitializePools(ITracer tracer, uint indexEntryCount)
            {
                if (stringPool == null)
                {
                    stringPool = new ObjectPool <LazyUTF8String>(tracer, Convert.ToInt32(indexEntryCount * PoolAllocationMultipliers.StringPool), objectCreator: () => new LazyUTF8String());
                }

                if (bytePool == null)
                {
                    bytePool = new BytePool(tracer, indexEntryCount);
                }
            }
Ejemplo n.º 5
0
        internal static void ReleaseBufferToPool(ref byte[] buffer)
        {
            if (buffer == null)
            {
                return;
            }

            BytePool bytePool = BytePools[GetPoolIndex(buffer.Length)];

            bytePool.Return(ref buffer);

            buffer = null;
        }
Ejemplo n.º 6
0
        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();
        }
 public static void RestoreRxByte(IRxStruct <byte> rxByte)
 {
     BytePool.Restore(rxByte);
 }
 public static IRxStruct <byte> GetRxByte()
 {
     return(BytePool.Take());
 }
Ejemplo n.º 9
0
        private static byte[] TakeBufferBytes(int size)
        {
            BytePool bytePool = BytePools[GetPoolIndex(size)];

            return(bytePool.Take());
        }