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 FileMapped::open_for_exchange and
adopt_stored on an exchange mapping 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. C# Dispose and C++ Close or destruction
trim the file to the last stored byte. In the Rust submodule,
FileMapped::open_for_exchange adopts a file's contents and
FileMapped::from_path_for_exchange starts with an empty logical slice.
Both trim the reservation on close or drop and preserve stored bytes that
the caller has yet to adopt. Use explicit close in C++ or Rust to handle
I/O errors.
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.
- .NET 11 provides the memory-mapping APIs.
- Platform.IO