public static PooledMemoryStream From(BufferManagerAllocator pool, byte[] buffer, int length)
        {
            var retval = new PooledMemoryStream(pool);

            retval.chunks.Add(buffer);
            retval.lengths.Add(buffer.Length);
            retval.currentChunk = buffer;
            retval.currentIndex = 0;
            retval.length       = length;

            return(retval);
        }
        private PooledSegment SerializeObject(object value)
        {
            using (var ms = new PooledMemoryStream(allocator))
            {
                new BinaryFormatter().Serialize(ms, value);

                var retval = new PooledSegment(allocator, (int)ms.Length);
                ms.Position = 0;
                ms.Read(retval.Array, 0, retval.Count);

                return(retval);
            }
        }
        private ByteBuffer SerializeObject(object value)
        {
            using (var ms = new PooledMemoryStream(allocator))
            {
                new BinaryFormatter().Serialize(ms, value);

                var retval = new ByteBuffer(allocator, allocator.Take((int)ms.Length), (int)ms.Length);
                ms.Position = 0;
                ms.Read(retval.Array, 0, retval.Length);

                return(retval);
            }
        }