苹果事件与通知

发布于 2024-09-13 09:52:12 字数 109 浏览 5 评论 0原文

我正在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

游魂 2024-09-20 09:52:12

如果您的目标是高性能和/或可靠性,分布式通知(即通过 NSDistributedNotificationCenter 发送的通知)很可能不是一个好的选择。以下是苹果公司自己对此主题的看法:

发布分布式通知是一项昂贵的操作。通知被发送到系统范围的服务器,该服务器将其分发到所有注册了分布式通知对象的任务。发布通知和通知到达另一个任务之间的延迟是无限的。事实上,当发布太多通知并且服务器队列已满时,通知可能会被丢弃。 http://开发人员。 apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSDistributedNotificationCenter_Class/Reference/Reference.html

根据您所说的“高性能”的含义,您可能想要研究分布式对象,或者普通的旧 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:

Posting a distributed notification is an expensive operation. The notification gets sent to a system-wide server that distributes it to all the tasks that have objects registered for distributed notifications. The latency between posting the notification and the notification’s arrival in another task is unbounded. In fact, when too many notifications are posted and the server’s queue fills up, notifications may be dropped. http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSDistributedNotificationCenter_Class/Reference/Reference.html

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).

飘过的浮云 2024-09-20 09:52:12

如果您同时控制发送方和接收方,则可以在两个进程之间打开一个套接字( 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文