是否可以直接在C#中打开内存映射文件,就像在windows中直接打开文件一样, 例如,我正在创建内存映射文件。通过以下代码。
using System;
using System.IO.MemoryMappedFiles;
namespace ConsoleApplication1
{
class Program
{
static void Main()
{
MemoryMappedFile mmf = MemoryMappedFile.CreateNew("test.txt", 5);
MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor();
var arun = new[] {(byte)'a', (byte)'r', (byte)'u', (byte)'n'};
for (int i = 0; i < arun.Length; i++)
accessor.Write(i, arun[i]);
Console.WriteLine("Memory-mapped file created!");
Console.ReadLine(); // pause till enter key is pressed
accessor.Dispose();
mmf.Dispose();
}
}
}
我需要直接打开文件。是否可以通过
打开文件Process.start("test.txt");
从另一个进程而不是通过代码读取值。
MemoryMappedFile mmf1 = MemoryMappedFile.OpenExisting("test.txt");
MemoryMappedViewAccessor accessor1 = mmf1.CreateViewAccessor();
var value = accessor1.ReadByte(4);
是否可以直接打开内存映射文件?请告诉我。
最佳答案
Starting with the .NET Framework version 4, you can use managed code to access memory-mapped files in the same way that native Windows functions access memory-mapped files, as described in Managing Memory-Mapped Files in Win32 in the MSDN Library.
关于c# - 直接从内存处理C#中的内存映射文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8968730/