Skip to content

PointerMemoryManager #1198

@MichalPetryka

Description

@MichalPetryka

Overview

PointerMemoryManager is a common concept among projects, allowing to pass native memory to async apis that take Memory.

API breakdown

public sealed class PointerMemoryManager<T> : MemoryManager<T>
{
    public PointerMemoryManager(T* pointer, int size);
    public override Span<T> GetSpan();
    public override MemoryHandle Pin(int elementIndex = 0);
    public override void Unpin();
    protected override void Dispose(bool disposing);
}

Usage example

byte* ptr = SomeApi(out int length);
using PointerMemoryManager<byte> 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature request 📬A request for new changes to improve functionality

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions