I would like to store a struct into a MemoryMappedFile, but this struct contains strings (with a max size which I know) that are reference type and therefore rejected by the MemoryMappedViewAccessor.
Do you know a good fixed-length string struct (value type) implementation? I can hard code the length if that is necessary (as arrays are reference types).
For example, I could instantiate it as:
TenCharsString myString = new TenCharsString("1234567890");
Decorating with the MarshalAs attribute
<MarshalAs (UnmanagedType.ByValTStr, SizeConst:=128)>
should work, but it does not.
Here’s a simple 10-character value type:
If unsafe code is an option, this works as well:
Full code: