LibUv Networking (#65)
This commit is contained in:
parent
ec6629fbe9
commit
5e2be2d7b6
69 changed files with 5612 additions and 586 deletions
57
Projects/Server/Buffers/MemoryPoolBlock.cs
Normal file
57
Projects/Server/Buffers/MemoryPoolBlock.cs
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace System.Buffers
|
||||
{
|
||||
/// <summary>
|
||||
/// Block tracking object used by the byte buffer memory pool. A slab is a large allocation which is divided into smaller blocks. The
|
||||
/// individual blocks are then treated as independent array segments.
|
||||
/// </summary>
|
||||
public sealed class MemoryPoolBlock : IMemoryOwner<byte>
|
||||
{
|
||||
private readonly int _offset;
|
||||
private readonly int _length;
|
||||
|
||||
/// <summary>
|
||||
/// This object cannot be instantiated outside of the static Create method
|
||||
/// </summary>
|
||||
internal MemoryPoolBlock(SlabMemoryPool pool, MemoryPoolSlab slab, int offset, int length)
|
||||
{
|
||||
_offset = offset;
|
||||
_length = length;
|
||||
|
||||
Pool = pool;
|
||||
Slab = slab;
|
||||
|
||||
Memory = MemoryMarshal.CreateFromPinnedArray(slab.Array, _offset, _length);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Back-reference to the memory pool which this block was allocated from. It may only be returned to this pool.
|
||||
/// </summary>
|
||||
public SlabMemoryPool Pool { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Back-reference to the slab from which this block was taken, or null if it is one-time-use memory.
|
||||
/// </summary>
|
||||
public MemoryPoolSlab Slab { get; }
|
||||
|
||||
public Memory<byte> Memory { get; }
|
||||
|
||||
~MemoryPoolBlock()
|
||||
{
|
||||
Pool.RefreshBlock(Slab, _offset, _length);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Pool.Return(this);
|
||||
}
|
||||
|
||||
public void Lease()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue