Skip to content

Abstraction for System.IO.MemoryMappedFiles #1042

Description

@vbreuss

Problem

System.IO.MemoryMappedFiles (MemoryMappedFile, MemoryMappedViewAccessor, MemoryMappedViewStream) has no abstraction. Code that memory-maps a file has no seam and cannot be exercised against MockFileSystem.

Scope

Core surface that would need mirroring:

  • MemoryMappedFile.CreateFromFile(...) (path and FileStream-based overloads), CreateNew(...), CreateOrOpen(...), OpenExisting(...)
  • MemoryMappedFile.CreateViewAccessor(...) → MemoryMappedViewAccessor
  • MemoryMappedFile.CreateViewStream(...) → MemoryMappedViewStream

Following the established pattern (cf. Testably.Abstractions.Compression), this would be a separate opt-in package exposing an IMemoryMappedFileFactory reachable via an extension method on IFileSystem (e.g. fileSystem.MemoryMappedFile()), with a real wrapper and a mock backed by the in-memory file storage.

Considerations / risks

  • MemoryMappedViewAccessor exposes SafeMemoryMappedViewHandle and Read/Write<T> of arbitrary structs at offsets — the mock would model these over the mock file's byte buffer, but pointer-level access (AcquirePointer) cannot be faithfully mocked.
  • Named maps (cross-process shared memory via mapName) are an OS/IPC concept with no in-memory analogue; scope the mock to file-backed maps and document named/cross-process maps as unsupported.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions