/
githubmirror
/
aspnetcore
Обзор
Документация
Войти
/
githubmirror
/
aspnetcore
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Shared/Buffers.MemoryPool/MemoryPoolBlock.cs
34 строки
1005 B
Brennan
Add IMemoryPoolFactory and cleanup memory pool while idle (#61554)
10 июн 2025, 00:09
Не верифицирован
10 июн 2025, 00:09
b24508e
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. using System.Buffers; using System.Runtime.InteropServices; namespace Microsoft.AspNetCore; /// <summary> /// Wraps an array allocated in the pinned object heap in a reusable block of managed memory /// </summary> internal sealed class MemoryPoolBlock : IMemoryOwner<byte> { internal MemoryPoolBlock(PinnedBlockMemoryPool pool, int length) { Pool = pool; var pinnedArray = GC.AllocateUninitializedArray<byte>(length, pinned: true); Memory = MemoryMarshal.CreateFromPinnedArray(pinnedArray, 0, pinnedArray.Length); } /// <summary> /// Back-reference to the memory pool which this block was allocated from. It may only be returned to this pool. /// </summary> public PinnedBlockMemoryPool Pool { get; } public Memory<byte> Memory { get; } public void Dispose() { Pool.Return(this); } }