【DSP开发】shared memory VS mailbox

275 篇文章 41 订阅 ¥39.90 ¥99.00
56 篇文章 18 订阅
博客探讨了在IPC(进程间通信)中,shared memory与mailbox两种机制的不同。shared memory允许进程间共享内存区域,类似于malloc,适合共享全局变量。而mailbox更像是管道,用于发送消息,支持多生产者和单消费者模式,消息读取后即被移除。选择哪种方式取决于具体需求。
摘要由CSDN通过智能技术生成

Hello,

Hi everyone,
I have a simple question. Could anyone explain to me the difference between Mailboxes and Shared Memory?

A “Shared memory” (shm) is some portion of memory that you can share between process and threads. Like a malloc, you have a fixed size memory area, and you can do nearly what you want with. (Reading of writing)

A Mailbox is more like a pipe. You push data (messages) on the pipe of indeterminate size (the mailbox as a fixed size that you can store multiples messages, but not exceeding the size of the mailbox)

Classic mailboxes are “One consumer multiple producers” but some types of mailbox allow to have multiple consumers (but I not sure this is a good idea) and you can put priority on messages with some other sort of mailboxes. You have too the ability to suspend a task (thread or process) on reading a mailbox, allowing it to wait for a new message.

Am I right, that both are possibilities for two or more tasks to exchange data?

Yes but not is the same way (as explained above.) The use of each depends on what you want to do.

If it for sharing global variables, shm is, as for me, the better way, if it for send private data, or give orders, Mailbox (or pipe) are the better.

Will a message send to a mailbox still be in the mailbox after another task read it?

No

Greetings from Germany,
Martin

Greetings from South of France, and have a good day playing with IPC :)

Manoel

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值