2021-04-22 22:40:40 +08:00
|
|
|
using System.IO;
|
|
|
|
using BililiveRecorder.Flv;
|
|
|
|
using Microsoft.IO;
|
|
|
|
|
|
|
|
namespace BililiveRecorder.ToolBox
|
|
|
|
{
|
|
|
|
internal class RecyclableMemoryStreamProvider : IMemoryStreamProvider
|
|
|
|
{
|
|
|
|
private readonly RecyclableMemoryStreamManager manager;
|
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
//manager.StreamFinalized += () =>
|
|
|
|
//{
|
|
|
|
// Debug.WriteLine("TestRecyclableMemoryStreamProvider: Stream Finalized");
|
|
|
|
//};
|
|
|
|
//manager.StreamDisposed += () =>
|
|
|
|
//{
|
|
|
|
// // Debug.WriteLine("TestRecyclableMemoryStreamProvider: Stream Disposed");
|
|
|
|
//};
|
|
|
|
}
|
|
|
|
|
2021-11-20 13:19:23 +08:00
|
|
|
public MemoryStream CreateMemoryStream(string tag) => this.manager.GetStream(tag);
|
2021-04-22 22:40:40 +08:00
|
|
|
}
|
|
|
|
}
|