LinksPlatform's Platform.Memory Class Library contains classes for memory management simplification. Here you can find multiple implementations of IMemory interface.
The data can be accessed using the raw pointer or by element's index and can be stored in volatile memory:
or in non-volatile memory:
Namespace: Platform.Memory
Forked from: Konard/LinksPlatform/Platform/Platform.Memory
NuGet package: Platform.Memory
C# FileMappedResizableDirectMemory, C++ FileMappedResizableDirectMemory, and
Rust FileMapped<T> share this format. The file contains the contiguous
native-endian bytes of the values, with no header or sidecar. Use the same
element size, representation, and endianness in each implementation. For
example, use C# ulong, C++ std::uint64_t, and Rust u64.
On open, the file length is the stored byte length. For a typed reader, the
element count is that length divided by sizeof(T) and the length must be a
multiple of sizeof(T). C# and C++ expose UsedCapacity in bytes and can open
any byte length. If you interpret their pointers as a typed array, check the
length before doing so. Rust open and adopt_stored return an invalid-data
error for an incomplete element. A byte-oriented reader can access all bytes.
The default working file reservation is page-rounded. C# and C++ permit
explicit byte-sized reservations, and Rust's low-level remap APIs permit
explicit file lengths. After a successful close, the file ends at the last
stored byte. C# uses Dispose, C++ uses Close or its destructor, and Rust
uses close or Drop. Rust's lower-level from_path and new preserve
existing stored bytes even when the caller adopts only a prefix. Use explicit
close in C++ or Rust when the caller needs to handle an I/O error.
Give the active writer exclusive control of the file and release separate mappings before closing. Read or exchange files after closing the writer. A headerless file created by an older implementation may already include page padding. Every complete element in that file counts as data, including zero values. Recovering the original logical length requires information from the application that wrote it.
See the implementation notes for C#, C++,
and Rust in the rust submodule. The Rust implementation is published
separately as platform-mem.
The fixture check exercises every
writer and reader combination.
PDF file with code for e-readers.