コード例 #1
0
 internal UnmanagedWriteBuffer(JsonOperationContext context, UnmanagedBuffersPool.AllocatedMemoryData allocatedMemoryData)
 {
     _context = context;
     _current = new Segment
     {
         Address    = (byte *)allocatedMemoryData.Address,
         Allocation = allocatedMemoryData,
         Used       = 0,
         Previous   = null
     };
 }
コード例 #2
0
        public void Dispose()
        {
            if (_buffer != null)
            {
                _context.ReturnMemory(_buffer);
                _buffer = null;
            }
            if (_compressionBuffer != null)
            {
                _context.ReturnMemory(_compressionBuffer);
                _compressionBuffer = null;
            }

            _stream.Dispose();
        }
コード例 #3
0
        /// <summary>
        /// Returns memory buffer to work with, be aware, this buffer is not thread safe
        /// </summary>
        /// <param name="requestedSize"></param>
        /// <param name="actualSize"></param>
        /// <returns></returns>
        public unsafe byte *GetNativeTempBuffer(int requestedSize, out int actualSize)
        {
            if (requestedSize == 0)
            {
                throw new ArgumentException(nameof(requestedSize));
            }

            if (_tempBuffer == null)
            {
                _tempBuffer = GetMemory(requestedSize);
            }
            else if (requestedSize > _tempBuffer.SizeInBytes)
            {
                ReturnMemory(_tempBuffer);
                _tempBuffer = GetMemory(requestedSize);
            }

            actualSize = _tempBuffer.SizeInBytes;
            return((byte *)_tempBuffer.Address);
        }
コード例 #4
0
        public void ReturnMemory(UnmanagedBuffersPool.AllocatedMemoryData buffer)
        {
            if (buffer.SizeInBytes == 0)
            {
                return;
            }

            if (_allocatedMemory == null)
            {
                _allocatedMemory = new Stack <UnmanagedBuffersPool.AllocatedMemoryData> [32];
            }
            var index = UnmanagedBuffersPool.GetIndexFromSize(buffer.SizeInBytes);

            if (index == -1)
            {
                Pool.Return(buffer);
                return;
            }
            if (_allocatedMemory[index] == null)
            {
                _allocatedMemory[index] = new Stack <UnmanagedBuffersPool.AllocatedMemoryData>();
            }
            _allocatedMemory[index].Push(buffer);
        }