in reply to Memory mapped file questions

The parts where C# writes the data to the file are:

accessor.Write(0, (char)de.Length); accessor.WriteArray(0, de, 0, de.Length);

That suggests that there will be a single byte written containing the length of the string, and then the string. Maybe consider confirming this using a hex viewer, like hexdump or Perl code like the following:

perl -nE 'BEGIN{ binmode $ARGV; $/=\16;}; say map {sprintf "%02x ", or +d $_}split //;' /path/to/file

You will want to look at open, binmode (or use that in open directly), then read to get the data, and then unpack (see its documentation in pack. Most likely, the c/a template will be what you want to read in a length-prefixed string. To make it readable, see Encode::decode to decode it from UTF-8 to printable.

Update: Added description of where the "interesting" part of writing the data happens in the C# code

Replies are listed 'Best First'.
Re^2: Memory mapped file questions
by faustf (Novice) on Oct 09, 2020 at 20:26 UTC
    Thanks for answer, i don't have a real file in HDD, C# create a data-file directly in memory ,i never used hexdump , your example include a path to file , what should I call ? thanks

      How much of your C# code do you understand?

      Reading your code, there is the line:

      MemoryMappedFile.CreateOrOpen("Test", 1000, MemoryMappedFileAccess.Rea +dWrite);

      This suggests that the code opens or creates a file named Test in the current directory, and as jcb suggests, you could use that as the filename.

      If this is your code, maybe you want to use a different approach than a memory mapped file. If this is not your code, consider talking to the original author about using a different serialization scheme, like JSON, or a well-defined binary layout, or just not using a memory mapped file when a plain file will do just as well.

        Msdn docet MemoryMappedFile.CreateOrOpen Metod: Creates a new empty memory-mapped file or opens an existing one IF one with the same name exists. (i assure not exist a file in my HDD with name Test ) if i wanted to open a file i would used this MemoryMappedFile.CreateFromFile Create a memory-mapped file from a disk file.

      Your C# code appears to be creating a file named "Test" in its current directory. You will want perl to open that file.

      Note that synchronization between memory-mapped files and the rest of the filesystem API is usually unspecified until msync() or its equivalent is called or the file is unmapped, so your data may not be actually written to the file until your C# program exits or performs some kind of synchronization call.