如何使用共享内存来共享程序中的数据

发布于 2024-12-24 01:51:14 字数 424 浏览 4 评论 0原文

我想在Linux上写一个“嵌入式控制系统”,

为了方便以后更新,我认为多进程比多线程更好

,所以,这个系统可能分为3个程序

  1. “进程",从别人那里读取一些输入数据并进行一些计算,然后将结果保存到共享内存

  2. "显示”,从共享内存中读取即时数据并选择一些数据在UI上显示(Qt编写)

  3. “数据库”,从共享内存中读取即时数据并保存一个周期内的数据,一开始会以二进制文件的形式保存,以后可能会改用sqlite

代替不,也许我会添加一个网络服务器来读取即时数据并通过浏览器显示它,

这里的问题是:

  1. 多进程真的更好多线程吗?

  2. 如果使用多进程,使用共享内存怎么样,有什么缺点。

I want to write a "embedded control system", on Linux

In order to make it easy to update in the future, i think multi-process is better than muti-thread

so, this system maybe separate into 3 program

  1. "process", read some input data from others and do some calculation, then save the result to shared memory

  2. "display", read instant data from shared memory and choose some data to display on UI(written by Qt)

  3. "database", read instant data from shared memory and save them in a period, data will be saved in binary files at first, and maybe use sqlite instead in the future

and nore, maybe i will add a web server to read the instant data and show it through the browser

here is the question:

  1. is multi-process really better multi-thread?

  2. If use multi-process, how about use shared memory, is there any disadvantage.

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

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

发布评论

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

评论(3

网名女生简单气质 2024-12-31 01:51:14

多进程真的比多线程更好吗?

取决于你想做什么。多处理强制系统组件之间严格分离,允许各个部分使用不同的凭据运行。它确实需要比多线程更复杂的通信机制,并且会产生一些开销。

如果使用多进程,使用共享内存怎么样,有什么缺点吗?

与使用套接字的明显替代方案相比,主要缺点是它限制整个系统只能在单个主机上运行。没有分布式计算。

is multi-process really better multi-thread?

Depends on what you want to do. Multiprocessing enforces a strict separation between system components, allowing for various parts to run with different credentials. It does require a more complicated communication mechanism than multithreading and incurs some overhead.

If use multi-process, how about use shared memory, is there any disadvantage.

The main disadvantage, compared to the obvious alternative of using sockets, is that it limits your entire system to running on a single host. No distributed computing.

邮友 2024-12-31 01:51:14

您已经在使用 Qt,它适合嵌入式系统。伟大的。

它具有良好的 TCP 套接字和 *nix 套接字 API,以及良好的数据流协议。除非您要求绝对出色的性能,否则我会选择安全、独立的流程。

You're already using Qt, which is suitable for embedded systems. Great.

It has good APIs for TCP sockets and *nix sockets, and good data streaming protocols. Unless you demand absolutely scorching performance, I would err on the side of secure, separate processes.

迟月 2024-12-31 01:51:14

三个进程的优点是受保护的地址空间可以防止进程之间不需要的通信。

三个进程的优点是受保护的地址空间阻碍了进程之间所需的通信。

进程间通信比线程间通信更慢且更难管理。

The upside of three processes is that the protected address space prevents unwanted communications between the processes.

The upside of three processes is that the protected address space hinders wanted communications between the processes.

Inter-process communication is slower and more difficult to manage than inter-thread comms.

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