Created
October 17, 2022 08:47
-
-
Save msymt/bb5e68da6e8a121cfcd04abfae3f0eb3 to your computer and use it in GitHub Desktop.
read 1byte and increment from MappedMemoryFile in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.IO.MemoryMappedFiles; | |
using System.Runtime.InteropServices; | |
public class HelloWorld | |
{ | |
static public void Main () | |
{ | |
string MappedMemoryFileName = "/tmp/mmf"; | |
using (var mmf = MemoryMappedFile.CreateFromFile(MappedMemoryFileName, FileMode.OpenOrCreate, MappedMemoryFileName)) | |
{ | |
int cur_loc = 0; | |
int prev_loc = 0; | |
int pivot = Convert.ToInt32(cur_loc ^ prev_loc); | |
// start: pivot, size: 1 | |
using (var accessor = mmf.CreateViewAccessor(pivot, 1)) | |
{ | |
// start position: 0 | |
var result = accessor.ReadByte(0); | |
Console.WriteLine("NUMBER: " + result); | |
result += 1; | |
accessor.Write(0, ref result); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ref