CommunityToolkit / CommunityToolkit/dotnet
PointerMemoryManager
- Dominant language
- C#
- Stars
- 3.8k
- Forks
- 400
- PR merge metrics
- No merged PRs in 30d
Description
### Overview
`PointerMemoryManager` is a common concept among projects, allowing to pass native memory to async apis that take Memory.
### API breakdown
```csharp
public sealed class PointerMemoryManager : MemoryManager
{
public PointerMemoryManager(T* pointer, int size);
public override Span GetSpan();
public override MemoryHandle Pin(int elementIndex = 0);
public override void Unpin();
protected override void Dispose(bool disposing);
}
```
### Usage example
```csharp
byte* ptr = SomeApi(out int length);
using PointerMemoryManager manager = new(ptr, length);
await SomeAsyncApi(manager.Memory);
```
### Breaking change?
No
### Alternatives
Define it in your project.
### Additional context
_No response_
### Help us help you
No, just wanted to propose this
Contributor guide
Assessment
This issue has not been assessed yet.