-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Remove slabs from the slab memory pool #30732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,52 +6,29 @@ | |
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. | ||
/// Wraps an array allocated in the pinned object heap in a reusable block of managed memory | ||
/// </summary> | ||
internal 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) | ||
internal MemoryPoolBlock(SlabMemoryPool pool, int length) | ||
{ | ||
_offset = offset; | ||
_length = length; | ||
|
||
Pool = pool; | ||
Slab = slab; | ||
|
||
Memory = MemoryMarshal.CreateFromPinnedArray(slab.PinnedArray, _offset, _length); | ||
var pinnedArray = GC.AllocateUninitializedArray<byte>(length, pinned: true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. https://docs.microsoft.com/en-us/dotnet/api/system.gc.allocateuninitializedarray?view=net-5.0 as an FYI to others reviewing. We didn't zero-allocate the array before, correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
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 SlabMemoryPool Pool { get; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove? Only spot I see this used is when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Its used in dispose There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. D'oh |
||
|
||
/// <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() | ||
{ | ||
} | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SlabMemoryPool
->SlablessMemoryPool
😋
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For real though, name change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'll rename it to PinnedBlockPool or something like that