You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
classProgram{staticvoidMain(){// 打开一个现有的内存映射文件using(MemoryMappedFilemmf=MemoryMappedFile.OpenExisting("sharedMemory")){// 创建一个视图流来访问内存映射文件using(MemoryMappedViewStreamstream=mmf.CreateViewStream()){// 读取数据从内存映射文件byte[]data=newbyte[1024];intbytesRead=stream.Read(data,0,data.Length);stringmessage=Encoding.UTF8.GetString(data,0,bytesRead);Console.WriteLine("Data read from shared memory: "+message);}}}}
内存共享写入
classProgram{staticvoidMain(){// 创建或打开一个内存映射文件using(MemoryMappedFilemmf=MemoryMappedFile.CreateOrOpen("sharedMemory",1024)){// 创建一个视图流来访问内存映射文件using(MemoryMappedViewStreamstream=mmf.CreateViewStream()){// 写入数据到内存映射文件byte[]data=Encoding.UTF8.GetBytes("Hello from Process 1");stream.Write(data,0,data.Length);Console.WriteLine("Data written to shared memory.");}}//Console.WriteLine("Press any key to exit...");//Console.ReadKey();}}
The text was updated successfully, but these errors were encountered:
内存共享读取
内存共享写入
The text was updated successfully, but these errors were encountered: