コード例 #1
0
ファイル: PacketGenerator.cs プロジェクト: ocoanet/ixy.cs
        private void InitMempool()
        {
            _mempool = MemoryHelper.AllocateMempool(BuffersCount);

            //Pre-fill all our packet buffers with some templates that can be modified later
            var buffers = new PacketBuffer[BuffersCount];

            for (int i = 0; i < BuffersCount; i++)
            {
                var buffer = _mempool.GetPacketBuffer();
                buffer.Size = (uint)PacketData.Length;
                buffer.WriteData(0, PacketData);
                var ipData = buffer.CopyData(14, 20);
                buffer.WriteData(24, (short)CalcIpChecksum(ipData));
                buffers[i] = buffer;
            }

            //Return them all to the mempool, all future allocations will return buffers with the data set above
            foreach (var buffer in buffers)
            {
                _mempool.FreeBuffer(buffer);
            }
        }