ファイル
YMM4-ProxyForge/ZeroDiskProxy/Memory/BufferPool.cs
T
routersys ff929da7a0 不要なMF相互運用ファイル削除とコード全体のリファクタリング
未使用のMFインターロップファイルを削除しました。
MfProxyEncoderのトランスコード進捗報告処理をTranscodeProgressReporterクラスに抽出しました。
キャンセル登録の型をIAsyncOperationWithProgressからIAsyncActionWithProgressに修正しました。
MfProxyEncoderFactory・MemoryBudget・PooledMemoryStream・CacheEntryViewModel等をプライマリコンストラクタ構文に変換しました。
ProxyCacheManagerのCacheKeyをrecord structに変換し、Equalsのオーバーライドを整理しました。
PooledBufferをmutableなstructに変更し、Interlocked.Exchangeによるスレッドセーフなディスポーズを実装しました。
FallbackStreamにRead(Span<byte>)・Write(ReadOnlySpan<byte>)・WriteAsyncの各オーバーロードを追加しました。
MemoryBudgetのTickCountを32ビットuintにキャストし、ラッピング演算の整合性を修正しました。
GetAllSnapshotsをList<T>ベースに変更し、配列の事前確保とArray.Resizeを除去しました。
ZeroDiskProxyVideoSourceのUpgrade適用ロジックをTryApplyUpgradeメソッドとして抽出しました。
ProxyGenerationItem・ByteFormatter・CacheEntryViewModelの文字列生成をstring.Createと補間文字列に統一しました。
PluginHostからResourceRegistryへの依存を取り除き、関連するDispose呼び出しを削除しました。
CheckExportWindowにDebug.Assertを追加し、スレッドプールの非同期継続から呼ばれた場合の前提条件違反を検出できるようにしました。
ClearAllのforeachでデコンストラクション構文をkeyプロパティの明示的な参照に変更しました。
CreateCoreメソッドをインスタンスメンバーからstaticメソッドに変更しました。
パターンマッチングをis { IsLoaded: true }・is { IsValid: true }形式に統一しました。
2026-03-24 17:09:37 +09:00

32 行
1011 B
C#

using System.Buffers;
namespace ZeroDiskProxy.Memory;
internal static class BufferPool
{
internal static byte[] Rent(int minimumLength) => ArrayPool<byte>.Shared.Rent(minimumLength);
internal static void Return(byte[] buffer, bool clearArray = false) => ArrayPool<byte>.Shared.Return(buffer, clearArray);
}
internal struct PooledBuffer : IDisposable
{
private byte[]? _buffer;
private readonly int _length;
internal PooledBuffer(int length)
{
_length = length;
_buffer = BufferPool.Rent(length);
}
internal readonly byte[] Array => _buffer ?? throw new ObjectDisposedException(nameof(PooledBuffer));
internal readonly int Length => _length;
internal readonly Span<byte> Span => _buffer is not null ? _buffer.AsSpan(0, _length) : throw new ObjectDisposedException(nameof(PooledBuffer));
public void Dispose()
{
var buf = Interlocked.Exchange(ref _buffer, null);
if (buf is not null)
BufferPool.Return(buf);
}
}