Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
181 views
in Technique[技术] by (71.8m points)

android - Share a file in volatile memory between processes without IPC

I have a large file that needs to be accessed (read-only) by several processes. I would like to load the file content into volatile memory at boot and then have the processes access it without communicating with each other.

I was thinking of setting aside physical memory for this purpose, and then hardcode the same physical address in each process. I would let each process make its own mapping to virtual memory, and have one of them write load the file content at boot. Is this possible on Linux (Android)? Is there a better way?

Some more perspective. The file is ~0.5 GB and it's important that read is as fast as possible. Yet the memory is restricted (embedded) so I don't want to have multiple copies of the same file in physical memory. Ideally, I would set aside a contiguous portion of physical memory.

From what I know about mmap, it doesn't load the file directly into memory, instead, it does so in a lazy manner, neither does it allow one to specify which physical memory to allocate to?

I'm thinking about using ION since I am on Android, but it seems to require IPC for sharing a memory handle.

question from:https://stackoverflow.com/questions/65935719/share-a-file-in-volatile-memory-between-processes-without-ipc

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Why don't just use classic RAM disk approach? With Linux you can add something like mkdir /tmp/memdisk; mount -t tmpfs -o size=512m myramdisk /tmp/memdisk; cp your_file /tmp/memdisk to one of your system init scripts and just access the file from here. The only real downside of it is that you need root access but for custom embedded devices this should not be a problem.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...