4

I want to share memory between two processes. One way I know is to mmap a shared file. However, I don't want to use a shared file, I want an anonymous mapping in the memory. How can I do that.

5 Answers 5

5

shm_open is your friend. You can unmap the shared region by using shm_unlink.

Sign up to request clarification or add additional context in comments.

Comments

5

Shared memory is what you want: http://en.wikipedia.org/wiki/Shared_memory

Since you're on linux, here you go: http://www.kernel.org/doc/man-pages/online/pages/man7/shm_overview.7.html

Comments

2

You can put your mmap'd file in the directory /dev/shm, which is mounted in most Linux systems as a tmpfs (that is, a memory-based filesystem).

Or your can mount your own tmpfs somewhere else in the directory tree (if you want other options).

Comments

0

shm_get is a good starting point, but you also need to read up about semaphores for mutual exclusion so that memory does not get corrupted.

Comments

0

Remember that on a NUMA system, if cores are on separate nodes they will access the memory at different speeds unless you pick a NUMA node which is equidistant from the cores.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.