示例#1
0
        /// <summary>
        /// Allocate a new RecyclableMemoryStream object
        /// </summary>
        /// <param name="memoryManager">The memory manager</param>
        /// <param name="id">A unique identifier which can be used to trace usages of the stream.</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>
        /// <param name="initialLargeBuffer">
        /// An initial buffer to use.
        /// This buffer will be owned by the stream and returned to the memory manager upon Dispose.
        /// </param>
        internal ChunkedMemoryStream(
            RecyclableMemoryManager memoryManager, Guid id, string?tag, int requestedSize, byte[]?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;
            }

            RecyclableMemoryManager.Events.Writer.MemoryStreamCreated(_id, _tag, requestedSize);
            _memoryManager.ReportStreamCreated();
        }
示例#2
0
 /// <summary>
 /// Allocate a new RecyclableMemoryStream object
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 /// <param name="id">A unique identifier which can be used to trace usages of the stream.</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 ChunkedMemoryStream(
     RecyclableMemoryManager memoryManager, Guid id, string?tag, int requestedSize)
     : this(memoryManager, id, tag, requestedSize, null)
 {
 }
示例#3
0
 /// <summary>
 /// Allocate a new RecyclableMemoryStream object.
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 /// <param name="id">A unique identifier which can be used to trace usages of the stream.</param>
 public ChunkedMemoryStream(RecyclableMemoryManager memoryManager, Guid id)
     : this(memoryManager, id, null, 0, null)
 {
 }
示例#4
0
 /// <summary>
 /// Allocate a new RecyclableMemoryStream object
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 /// <param name="id">A unique identifier which can be used to trace usages of the stream.</param>
 /// <param name="tag">A string identifying this stream for logging and debugging purposes</param>
 public ChunkedMemoryStream(RecyclableMemoryManager memoryManager, Guid id, string?tag)
     : this(memoryManager, id, tag, 0, null)
 {
 }
示例#5
0
 /// <summary>
 /// Allocate a new RecyclableMemoryStream object.
 /// </summary>
 /// <param name="memoryManager">The memory manager</param>
 public ChunkedMemoryStream(RecyclableMemoryManager memoryManager)
     : this(memoryManager, Guid.NewGuid(), null, 0, null)
 {
 }