/// <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(); }
/// <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) { }
/// <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) { }
/// <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) { }
/// <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) { }