Ejemplo n.º 1
0
        private void AllocNextChunk(int minimumChunkSize)
        {
            int newChunkSize;

            if (_currentChunk.Length > (int.MaxValue / 2))
            {
                newChunkSize = int.MaxValue;
            }
            else
            {
                newChunkSize = _currentChunk.Length * 2;
            }
            if (minimumChunkSize > newChunkSize)
            {
                newChunkSize = minimumChunkSize;
            }
            byte[] newChunk = _bufferManager.TakeBuffer(newChunkSize);
            if (_chunkCount == _chunks.Length)
            {
                byte[][] newChunks = new byte[_chunks.Length * 2][];
                Array.Copy(_chunks, newChunks, _chunks.Length);
                _chunks = newChunks;
            }
            _chunks[_chunkCount++] = newChunk;
            _currentChunk          = newChunk;
            _currentChunkSize      = 0;
        }
Ejemplo n.º 2
0
        void AllocNextChunk(int minimumChunkSize)
        {
            int newChunkSize;

            if (currentChunk.Length > (int.MaxValue / 2))
            {
                newChunkSize = int.MaxValue;
            }
            else
            {
                newChunkSize = currentChunk.Length * 2;
            }
            if (minimumChunkSize > newChunkSize)
            {
                newChunkSize = minimumChunkSize;
            }
            byte[] newChunk = bufferManager.TakeBuffer(newChunkSize);
            if (chunkCount == chunks.Length)
            {
                byte[][] newChunks = new byte[chunks.Length * 2][];
                Array.Copy(chunks, newChunks, chunks.Length);
                chunks = newChunks;
            }
            chunks[chunkCount++] = newChunk;
            currentChunk         = newChunk;
            currentChunkSize     = 0;
        }
Ejemplo n.º 3
0
 public void Reinitialize(int initialSize, int maxSizeQuota, int effectiveMaxSize, InternalBufferManager bufferManager)
 {
     Fx.Assert(!_initialized, "Clear must be called before re-initializing stream");
     _maxSizeQuota     = maxSizeQuota;
     _maxSize          = effectiveMaxSize;
     _bufferManager    = bufferManager;
     _currentChunk     = bufferManager.TakeBuffer(initialSize);
     _currentChunkSize = 0;
     _totalSize        = 0;
     _chunkCount       = 1;
     _chunks[0]        = _currentChunk;
     _initialized      = true;
 }