UNIX域套接字与共享内存(映射文件) [英] UNIX Domain sockets vs Shared Memory (Mapped File)

查看:218
本文介绍了UNIX域套接字与共享内存(映射文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能说出,与共享内存(或备用内存映射文件)相比,UNIX域套接字的速度有多慢?

Can anyone tell, how slow are the UNIX domain sockets, compared to Shared Memory (or the alternative memory-mapped file)?

谢谢.

推荐答案

更多的是设计问题,而不是速度(共享内存更快),域套接字肯定是UNIX风格的,并且少做很多问题.在选择方面,请事先了解:

It's more a question of design, than speed (Shared Memory is faster), domain sockets are definitively more UNIX-style, and do a lot less problems. In terms of choice know beforehand:

域套接字的优势

  • 阻止和非阻止模式以及它们之间的切换
  • 您无需在任务完成后释放它们

域套接字的缺点

  • 必须以线性方式读取和写入

共享内存优势

  • 非线性存储
  • 将永远不会阻止
  • 多个程序可以访问它

共享内存的缺点

  • 需要锁定实现
  • 需要手动释放,即使没有被任何程序使用

这就是我现在能想到的.但是,我每天都会使用域套接字-更不用说重新实现它们来进行分布式计算要容易得多.共享内存的速度增益将因安全设计的需要而丢失.但是,如果您确切地知道自己在做什么,并使用正确的内核调用,则可以 使用共享内存来提高速度.

That's all I can think of now. However, I'd go with domain sockets any day -- not to mention that it's a lot easier then to reimplement them to do distributed computing. The speed gain of Shared Memory will be lost because of the need of a safe design. However, if you know exactly what you're doing, and use the proper kernel calls, you can achieve greater speed with Shared Memory.

这篇关于UNIX域套接字与共享内存(映射文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆