Note that there are some explanatory texts on larger screens.

plurals
  1. POWrite string data to MemoryMappedFile
    primarykey
    data
    text
    <p>I am following this tutorial <a href="http://www.c-sharpcorner.com/uploadfile/b942f9/using-memory-mapped-files/" rel="nofollow">here</a></p> <p>I am having a hard time figuring out how to get a string "THIS IS A TEST MESSAGE" to store in the memory mapped file and then pull it out on the other side. The tutorial says to use byte array. Forgive me I am new to this and trying on my own first.</p> <p>Thanks, Kevin</p> <pre><code>##Write to mapped file using System; using System.IO.MemoryMappedFiles; class Program1 { static void Main() { // create a memory-mapped file of length 1000 bytes and give it a 'map name' of 'test' MemoryMappedFile mmf = MemoryMappedFile.CreateNew("test", 1000); // write an integer value of 42 to this file at position 500 MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor(); accessor.Write(500, 42); Console.WriteLine("Memory-mapped file created!"); Console.ReadLine(); // pause till enter key is pressed // dispose of the memory-mapped file object and its accessor accessor.Dispose(); mmf.Dispose(); } } ##read from mapped file using System; using System.IO.MemoryMappedFiles; class Program2 { static void Main() { // open the memory-mapped with a 'map name' of 'test' MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("test"); // read the integer value at position 500 MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor(); int value = accessor.ReadInt32(500); // print it to the console Console.WriteLine("The answer is {0}", value); // dispose of the memory-mapped file object and its accessor accessor.Dispose(); mmf.Dispose(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload