-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
26 lines (21 loc) · 749 Bytes
/
Program.cs
File metadata and controls
26 lines (21 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using System;
using System.Buffers;
// MemoryPool<T> Class
// https://learn.microsoft.com/en-us/dotnet/api/system.buffers.memorypool-1?view=net-8.0
// https://github.com/dotnet/runtime/blob/main/src/libraries/System.Memory/src/System/Buffers/MemoryPool.cs
// Use the singleton pool
// https://stackoverflow.com/questions/73661594/whats-the-point-of-c-sharp-memory-pool
using var owner = MemoryPool<double>.Shared.Rent(100);
Memory<double> mem = owner.Memory;
MemoryPool<byte> memoryPool = MemoryPool<byte>.Shared;
IMemoryOwner<byte> memoryOwner = memoryPool.Rent(1024);
Memory<byte> memory = memoryOwner.Memory;
try
{
Span<byte> span = memory.Span;
span[0] = 42;
}
finally
{
memoryOwner.Dispose();
}