BililiveRecorder/BililiveRecorder.Core/RecyclableMemoryStreamProvider.cs

34 lines
1.0 KiB
C#
Raw Normal View History

2021-02-23 18:03:37 +08:00
using System.IO;
using BililiveRecorder.Flv;
using Microsoft.IO;
namespace BililiveRecorder.Core
{
internal class RecyclableMemoryStreamProvider : IMemoryStreamProvider
2021-02-23 18:03:37 +08:00
{
private readonly RecyclableMemoryStreamManager manager;
2021-02-23 18:03:37 +08:00
public RecyclableMemoryStreamProvider()
{
const int K = 1024;
const int M = K * K;
this.manager = new RecyclableMemoryStreamManager(32 * K, 64 * K, 64 * K * 32)
{
MaximumFreeSmallPoolBytes = 32 * M,
MaximumFreeLargePoolBytes = 64 * K * 32,
};
2021-02-23 18:03:37 +08:00
//manager.StreamFinalized += () =>
//{
// Debug.WriteLine("TestRecyclableMemoryStreamProvider: Stream Finalized");
//};
//manager.StreamDisposed += () =>
//{
// // Debug.WriteLine("TestRecyclableMemoryStreamProvider: Stream Disposed");
//};
}
public MemoryStream CreateMemoryStream(string tag) => this.manager.GetStream(tag);
2021-02-23 18:03:37 +08:00
}
}