記憶體對應檔案(Memory Mapped File)功能

  • 1959
  • 0

摘要:記憶體對應檔案(Memory Mapped File)功能

 

//ConsoleApplication1.exe

using(varmmf = MemoryMappedFile.CreateNew("test", 1000))

            using(varstream = mmf.CreateViewStream())

            {

                varwriter = newBinaryWriter(stream);

                writer.Write("kylin test");

                varstartInfo = newProcessStartInfo("ConsoleApplication2.exe");

                startInfo.UseShellExecute = false;

                Process.Start(startInfo).WaitForExit();

            }

 

//ConsoleApplication2.exe

staticvoidMain(string[] args)

        {

            using(varmmf = MemoryMappedFile.OpenExisting("test"))

            using(varstream = mmf.CreateViewStream())

            {

                varreader = newBinaryReader(stream);

                Console.WriteLine(reader.ReadString());

            }

            Console.ReadKey();

        }