Skip to content

Uniform on-disk format: C# truncates mapped files to UsedCapacity bytes, mem-rs keeps whole pages #101

Description

@konard

Problem

The three implementations persist and reopen files differently (probe P7, linksplatform/mem-rs#50 table):

C# 0.4.1 C++ Rust FileMapped 0.6.2
Size while open ReservedCapacity ReservedCapacity whole pages ≥ MIN_FILE_SIZE
Size after close truncated to UsedCapacity bytes (e.g. 10) not truncated (Close() is empty, #88) stays page-rounded
Logical length on reopen whole file length whole file length whole elements, adopted by open

So a file written by mem-rs and opened by C# reports the zero page padding as used data. A file written by C# opens in mem-rs with any trailing partial element silently dropped (verified, see linksplatform/mem-rs#50).

Proposed solution (decision needed)

  1. Write down the format in a shared spec (README of each implementation): raw native T array, no header, logical length = file length / sizeof(T).
  2. Choose one close policy for all three. Recommended: mem-rs semantics. Keep whole pages, and record the logical length either (a) by truncating to the used length on close, which C# already does and mem-rs could do in Drop, or (b) in an optional 8-byte header / sidecar. (a) is compatible with all existing data.
  3. Add cross-implementation fixture tests: files written by C# are read by Rust and C++, and the other way round.

Related: linksplatform/mem-rs#50, #88, #87.


Part of #94 (catch up with mem-rs). Analysis and evidence: case study.

Metadata

Metadata

Assignees

No one assigned

    Labels

    cppcsharpdocumentationenhancementmem-rs-parity

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions