Operating System - HP-UX
1827806 Members
2261 Online
109969 Solutions
New Discussion

what is a shared memory mapped file?

 
SOLVED
Go to solution
Byron Myers
Trusted Contributor

what is a shared memory mapped file?

What are the differences between shared memory, shared memory mapped files, and shared libraries?
If you can focus your eyes far and straight enough ahead of yourself, you can see the back of your head.
2 REPLIES 2
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: what is a shared memory mapped file?

Hi Byron,

Shared memory is just what is sounds like. An area of memory that can be shared among processes. The typical method is a group of processes agree on a protocol for building a 'key' usually using the ftok function.

Then a process creates a shared memory segment
using shmget with IPC_CREAT set. This process can also set the permissions as to who can read and write to this segment. The processes actually attach to the segment via the shmat system call.
man shmget, ftok, shmctl, shmat, shmdt for details.

Memory mapped files are an extension of this and use the mmap system call to completely map a disk based file to an area of shared memory. Once that is done, all the standard file i/o operations read, write, etc. work except that they are writing to memory and thus are very fast. This is typically used to store lookup tables and scratchpad files for related processes. Man mmap for details.

Shared libraries enable many processes that can be totally unrelated to use a single set of instructions (text) and thus save memory on a machine-wide basis. For example, the printf function's instructions might be shared by hundreds of processes. This sharing is possible because the instructions (text) do not change; if a shared library module also includes data (and the vast m ajority do) then
each process gets it own copy of the data space while sharing text space.

Hope this clears it up a bit, Clay
If it ain't broke, I can fix that.
Byron Myers
Trusted Contributor

Re: what is a shared memory mapped file?

Thanks, very good explanation. points comming. Please see follow up question on shared libraries to be posted soon.
If you can focus your eyes far and straight enough ahead of yourself, you can see the back of your head.