苹果事件与通知
我正在 macos X 中寻找高性能进程间通信系统。
最好的系统是什么? AppleEvents
还是 NSNotifications
?
I am looking for a high performance inter process communication system in macos X.
What is the best system? AppleEvents
or NSNotifications
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的目标是高性能和/或可靠性,分布式通知(即通过 NSDistributedNotificationCenter 发送的通知)很可能不是一个好的选择。以下是苹果公司自己对此主题的看法:
根据您所说的“高性能”的含义,您可能想要研究分布式对象,或者普通的旧 Unix IPC 机制(套接字、管道、共享内存等)。
Distributed notifications (i.e. notifications sent through NSDistributedNotificationCenter) are most likely not a good option if your goal is high performance and/or reliability. Here is Apple's own take on this subject:
Depending on what you mean by "high performance", you might want to look into distributed objects, or plain old Unix IPC mechanisms (sockets, pipes, shared memory etc).
如果您同时控制发送方和接收方,则可以在两个进程之间打开一个套接字( man socketpair ),这是相当高性能的。您还可以在共享位置(例如 /tmp )打开一个文件,然后从一个进程写入该文件并从另一个进程读取该文件,这是相当快的。您还可以在本地计算机上打开两个 TCP/IP 端口,每个进程一个,然后“通过网络”从一个端口发送到另一个端口。
如果您仅有的两个选择是 NSNotifications 或 AppleEvents,那么 AppleEvents 可能会表现得更好。
If you control both the sender and the recipient, you can open a socket between the two processes ( man socketpair ), which is quite high performance. You can also open a file in a shared location ( like /tmp ) and write to it from one process and read from the other, which is quite speedy. You can also open two TCP/IP ports on the local machine, one in each process, and then send from one to the other "over the network".
If your only two choices are NSNotifications or AppleEvents, well, AppleEvents will likely perform better.