简体   繁体   English

ram中的共享内存或命名管道?

[英]Shared memory or named pipes in ram?

I want to communicate between two different programs. 我想在两个不同的程序之间进行通信。 A modded ambilight program which outputs led information and my own program that reads this information. 一个改装的流光溢彩程序,输出有关信息和我自己的程序,读取此信息。

I read about named pipes and shared memory. 我读到了命名管道和共享内存。 But for me it is not clear where the data is stored. 但对我来说,目前还不清楚数据的存储位置。 Due to the fact that i will exchange a lot of data i do not want to write this data to disk every time. 由于我将交换大量数据,我不想每次都将这些数据写入磁盘。 I am using a raspberry Pi and the sd card should last for some more time ;) 我正在使用覆盆子Pi,SD卡应该可以使用更长的时间;)

So the basic question is: with what methode can i exchange information to the other end without writing to the disk? 所以基本的问题是:用什么方法可以在不写入磁盘的情况下将信息交换到另一端? I am not sure if shared memory is written to ram, i want to make this clear. 我不确定共享内存是否写入ram,我想明确这一点。 As another idea i read about is /dev/shm which should be a ram disk. 我读到的另一个想法是/ dev / shm,它应该是一个ram磁盘。 Can i also use named pipes for this location and will the information than be saved in ram? 我是否也可以在此位置使用命名管道,而不是保存在ram中的信息?

whats the best way to go? 什么是最好的方式去? thanks :) 谢谢 :)

I read about named pipes and shared memory. 我读到了命名管道和共享内存。 But for me it is not clear where the data is stored. 但对我来说,目前还不清楚数据的存储位置。

In both cases, data is stored in memory (named pipes look like they reside on filesystem, but actual data is stored on memory). 在这两种情况下,数据都存储在内存中(命名管道看起来就像它们驻留在文件系统上,但实际数据存储在内存中)。

What method is better, it depends on actual application. 什么方法更好,这取决于实际应用。 Pipes have fairly limited buffer (most likely 64kb ) and writing to it will block when buffer is full. 管道具有相当有限的缓冲区(最可能是64kb ),并且当缓冲区已满时,写入将阻塞。 Shared memory can be arbitrarily large, but on the downside, shared memory is, well, just like that - plain memory. 共享内存可以任意大,但在不利方面,共享内存就像那样 - 普通内存。 You have to take care about synchronization etc yourself. 你必须自己照顾同步等。

Shared memory and named pipes (and unix domain sockets) IPC won't write to your sdcard unless you allocate more memory than the available physical RAM which is either 256MB or 512MB depending on your raspberrypi model. 共享内存和命名管道(以及unix域套接字)IPC将不会写入您的SD卡,除非您分配的内存超过256MB或512MB的可用物理RAM,具体取决于您的raspberrypi模型。 If you do so it will start swapping and will probably slow down. 如果你这样做,它将开始交换,并可能会放慢速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM