Exemplo n.º 1
0
        public async Task <ArraySegment <byte> > AllocateAsync(int size)
        {
            var offset = -1;
            var blocks = SizeToBlocks(size);

            _event.Reset();
            while ((offset = _allocator.Allocate(blocks)) == -1)
            {
                await _event.WaitAsync();
            }

            return(new ArraySegment <byte>(_buffer, offset * BlockSize, size));
        }
Exemplo n.º 2
0
        public ArraySegment <byte> AllocateAsync(int sizeBytes)
        {
            int offset;
            var blocks = SizeToBlocks(sizeBytes);

            lock (locker)
            {
                while ((offset = _allocator.Allocate(blocks)) == -1)
                {
                    Monitor.Wait(locker);
                }

                return(new ArraySegment <byte>(_buffer, offset * BlockSize, sizeBytes));
            }
        }