Skip to content

SafeBufferMemoryManager #1197

@MichalPetryka

Description

@MichalPetryka

Overview

Exposing a MemoryManager that would make access to memory mapped files easier would help projects interacting with them.

API breakdown

public sealed class SafeBufferMemoryManager : MemoryManager<byte>
{
    public SafeBufferMemoryManager(SafeBuffer buffer);
    public override Span<byte> GetSpan();
    public override MemoryHandle Pin(int elementIndex = 0);
    public override void Unpin();
    protected override void Dispose(bool disposing);
}

public static class MemoryMappedFileExtensions
{
    public static SafeBufferMemoryManager CreateMemoryManager(this MemoryMappedFile file);
    public static SafeBufferMemoryManager CreateMemoryManager(this MemoryMappedFile file, long offset, int size);
    public static SafeBufferMemoryManager CreateMemoryManager(this MemoryMappedFile file, long offset, int size, MemoryMappedFileAccess access);
}

Usage example

using MemoryMappedFile file = ...;
using SafeBufferMemoryManager memoryManager = file.CreateMemoryManager();
SomeApi(memoryManager.Memory.Span);

Breaking change?

No

Alternatives

dotnet/runtime#37227

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