Ejemplo n.º 1
0
 public override OwnedMemory <byte> Rent(int minimumBufferSize)
 {
     if (minimumBufferSize > _bufferSize)
     {
         ExceptionHelper.RequestedBufferTooLarge();
     }
     if (_buffers.TryDequeue(out EphemeralOwnedMemory result))
     {
         result.Lease();
         return(result);
     }
     lock (_buffers)
     {
         if (_currentAllocatedOffset >= _totalAllocated)
         {
             ExceptionHelper.OutOfAvailableBuffers();
         }
         var buffer = new EphemeralOwnedMemory(_currentAllocatedOffset, _bufferSize, this);
         _currentAllocatedOffset += _bufferSize;
         return(buffer);
     }
 }
Ejemplo n.º 2
0
 internal void Return(EphemeralOwnedMemory ephemeralBuffer) => _buffers.Enqueue(ephemeralBuffer);