×

# C# 文件映射内存共享

hqy hqy 发表于2026-04-08 16:57:10 浏览8 评论0

抢沙发发表评论

# C# 文件映射内存共享

代码

Global\ 前缀是为了全局共享,比如 windows 服务程序 和一般程序进行共享时,不加全局前缀无法共享

C#
byte[] bytes = new byte[1024];MemoryMappedFile mmf = MemoryMappedFile.CreateOrOpen("Global\\key", bytes.Length);MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor();accessor.WriteArray(0, bytes, 0, bytes.Length);MemoryMappedFile mmf1 = MemoryMappedFile.CreateOrOpen("Global\\key", bytes.Length);MemoryMappedViewAccessor accessor1 = mmf1.CreateViewAccessor();accessor1.ReadArray(0, bytes, 0, bytes.Length);//当所有对象释放后,内存失效


打赏

本文链接:https://kinber.cn/post/6411.html 转载需授权!

分享到:


推荐本站淘宝优惠价购买喜欢的宝贝:

image.png

 您阅读本篇文章共花了: 

群贤毕至

访客