示例#1
0
        private static LinearBucketSizeBufferPool bufferPool = null; // Note that this buffer pool is thread safe

        public static void StaticInit(UInt32 maxPayloadWithID)
        {
            if (maxPayloadWithID > MaxPayloadWithIDOverUdp)
            {
                throw new ArgumentOutOfRangeException(String.Format("You supplied a max payload (with id) of {0} but the max is {1}", maxPayloadWithID, MaxPayloadWithIDOverUdp));
            }

            lock (typeof(Cdp))
            {
                if (bufferPool != null)
                {
                    throw new InvalidOperationException("Static Initialization for Cdp already done");
                }
                bufferPool = new LinearBucketSizeBufferPool(maxPayloadWithID + HeaderLengthWithPayloadID, 64, 256, 4);
            }
        }
示例#2
0
        public void TestMethod1()
        {
            LinearBucketSizeBufferPool bufferPool = new LinearBucketSizeBufferPool(10, 4, 20, 5);

            bufferPool = new LinearBucketSizeBufferPool(400, 10, 1, 0);

            bufferPool.AssertBufferCount(0, 0);

            Byte[] temp = bufferPool.GetBuffer(0);
            bufferPool.AssertBufferCount(1, 1);
            bufferPool.FreeBuffer(temp);
            bufferPool.AssertBufferCount(0, 1);

            temp = bufferPool.GetBuffer(400);
            bufferPool.AssertBufferCount(1, 1);
            bufferPool.FreeBuffer(temp);
            bufferPool.AssertBufferCount(0, 1);
        }