Пример #1
0
        internal MessageBufferPool(MessageBufferProducer <T> messageProducer, int maxBuffers, int chunkSize, int chunksPerBlock, int maxPooled)
        {
#if DEBUG
            if (messageProducer == null)
            {
                throw new ArgumentNullException("messageProducer");
            }
#endif

            poolAmount    = maxPooled;
            pool          = new Queue <T>(maxPooled);
            producer      = messageProducer;
            bufferManager = new BufferManager(maxBuffers, chunkSize, chunksPerBlock);

            // Pre-allocate the amount of maxPooled objects we want to have

            T preAllocated;

            for (var i = 0; i < poolAmount; ++i)
            {
                if (tryAllocate(out preAllocated))
                {
                    if (!TryPush(preAllocated))
                    {
                        //TODO: Error
                    }
                }
                else
                {
                    //TODO: Error
                }
            }
        }
Пример #2
0
 internal MessageBufferPool(MessageBufferProducer <T> messageProducer)
     : this(messageProducer, 5, 1024, 1024, 1024)
 {
 }