示例#1
0
        /// <summary>
        /// Constructs a new <see cref="RecyclableMemoryStream"/> object.
        /// </summary>
        /// <param name="memoryManager">The memory manager</param>
        /// <param name="requestedSize">The initial requested size to prevent future allocations</param>
        /// <param name="tag">A string identifying this stream for logging and debugging purposes</param>
        /// <param name="initialLargeBuffer">
        /// This buffer will be owned by the stream and returned to the memory manager upon Dispose.
        /// </param>
        internal RecyclableMemoryStream(
            RecyclableMemoryManager memoryManager,
            long requestedSize,
            Guid id,
            string?tag,
            RecyclableBuffer?initialLargeBuffer)
            : base(Array.Empty <byte>())
        {
            _memoryManager = memoryManager ?? throw new ArgumentNullException(nameof(memoryManager));
            _id            = id;
            _tag           = tag;

            if (requestedSize < memoryManager.BlockSize)
            {
                requestedSize = memoryManager.BlockSize;
            }

            if (initialLargeBuffer == null)
            {
                EnsureCapacity(requestedSize);
            }
            else
            {
                _largeBuffer = initialLargeBuffer;
            }

            if (_memoryManager.GenerateCallStacks)
            {
                AllocationStack = Environment.StackTrace;
            }

            _memoryManager.ReportStreamCreated();
        }
 public RecyclableBuffer(RecyclableMemoryManager manager, byte[] buffer, int baseLength, string?tag)
 {
     Manager    = manager ?? throw new ArgumentNullException(nameof(manager));
     Buffer     = buffer ?? throw new ArgumentNullException(nameof(buffer));
     BaseLength = baseLength;
     Tag        = tag;
 }
示例#3
0
 /// <summary>
 /// Constructs a new <see cref="RecyclableMemoryStream"/> object.
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 /// <param name="tag">A string identifying this stream for logging and debugging purposes</param>
 /// <param name="requestedSize">The initial requested size to prevent future allocations</param>
 public RecyclableMemoryStream(RecyclableMemoryManager memoryManager, string?tag, long requestedSize)
     : this(memoryManager, requestedSize, Guid.Empty, tag, default)
 {
 }
示例#4
0
 /// <summary>
 /// Constructs a new <see cref="RecyclableMemoryStream"/> object.
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 /// <param name="tag">A string identifying this stream for logging and debugging purposes</param>
 public RecyclableMemoryStream(RecyclableMemoryManager memoryManager, string?tag)
     : this(memoryManager, 0, Guid.Empty, tag, default)
 {
 }
示例#5
0
 /// <summary>
 /// Constructs a new <see cref="RecyclableMemoryStream"/> object.
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 public RecyclableMemoryStream(RecyclableMemoryManager memoryManager)
     : this(memoryManager, 0, Guid.Empty, null, default)
 {
 }
 public RecyclableArrayPool(RecyclableMemoryManager memoryManager)
 {
     MemoryManager = memoryManager ?? throw new ArgumentNullException(nameof(memoryManager));
 }