广播传输和性能

发布于 2024-11-26 23:38:30 字数 161 浏览 1 评论 0原文

我猜测广播消息被发布到消息中 接收线程的队列并通过循环器传递。广播是在消息队列中的其他消息之前传递的还是只是附加到队列的末尾?我没有具体的需求或类似的东西,只是出于好奇而想知道。

在服务和 Activity 之间使用 IPC 广播的性能开销(CPU 和内存)是多少?

GL

I am guessing that the broadcast messages are posted to the message
queue of the receiving thread and delivered through the looper. Are the broadcasts delivered before other messages in the message queue or just appended to the end of the queue? I have no specific need or anything like that, just wanted to know out of curiosity.

What is the performance overhead (CPU and memory) for using broadcasts for IPC between a service and an Activity?

GL

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

↘紸啶 2024-12-03 23:38:30

广播是在消息队列中的其他消息之前传递的还是只是附加到队列的末尾?

我认为他们只是排在队列的最后。测试这一点的简单方法是 post() 将几个 Runnables 发送到队列,每个队列休眠一段时间,然后向自己发送广播。如果Runnables在广播之前全部处理完毕,则广播结束。如果广播在后面的 Runnables 之前处理,那么它会在前面注入。

在服务和 Activity 之间使用 IPC 广播的性能开销(CPU 和内存)是多少?

正如@jlindenbaum 所说,适度。我不建议尝试启动数千个东西,并且对于进程内工作有更轻量级的解决方案(例如,Messenger)。

Are the broadcasts delivered before other messages in the message queue or just appended to the end of the queue?

I think they just go on the end of the queue. The easy way to test this is to post() a couple of Runnables to the queue that each sleep for a bit, then send yourself a broadcast. If the Runnables are all processed before the broadcast, it went to the end. If the broadcast is processed before later Runnables, then it got injected at the front.

What is the performance overhead (CPU and memory) for using broadcasts for IPC between a service and an Activity?

Modest, as @jlindenbaum suggests. I wouldn't suggest trying to fire off thousands of the things, and there are lighter-weight solutions for in-process work (e.g., Messenger).

眼睛会笑 2024-12-03 23:38:30

我从未注意到使用此功能的设备会承受很大的压力。

这是我发现的唯一“理智”的方式,可以在服务和活动之间进行通信,而不会导致 UI 线程出现问题。

I've never noticed a considerable strain on devices using this.

It's the only "sane" way, that I've found, to communicate between a Service and an Activity without causing issues on UI threads.

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