This articleneeds additional citations forverification. Please helpimprove this article byadding citations to reliable sources. Unsourced material may be challenged and removed. Find sources: "Shared memory" – news ·newspapers ·books ·scholar ·JSTOR(September 2025) (Learn how and when to remove this message) |

Incomputer science,shared memory ismemory that may be simultaneously accessed by multipleprograms with an intent to provide communication among them or avoid redundant copies. Shared memory is an efficient means of passing data between programs. Depending on context, programs may run on a single processor or on multiple separate processors.
Using memory for communication inside a single program, e.g. among its multiplethreads, is also referred to as shared memory.

In computer hardware,shared memory refers to a (typically large) block ofrandom access memory (RAM) that can be accessed by several differentcentral processing units (CPUs) in amultiprocessor computer system.
Shared memory systems may use:[1]
A shared memory system is relatively easy to program since all processors share a single view of data and the communication between processors can be as fast as memory accesses to the same location. The issue with shared memory systems is that many CPUs need fast access to memory and will likelycache memory, which has two complications:
Technologies likecrossbar switches,Omega networks,HyperTransport orfront-side bus can be used to dampen the bottleneck-effects.
In case of aHeterogeneous System Architecture (processor architecture that integrates different types of processors, such asCPUs andGPUs, with shared memory), thememory management unit (MMU) of the CPU and theinput–output memory management unit (IOMMU) of the GPU have to share certain characteristics, like a common address space.
The alternatives to shared memory aredistributed memory anddistributed shared memory, each having a similar set of issues.
In computer software,shared memory is either
Since both processes can access the shared memory area like regular working memory, this is a very fast way of communication (as opposed to other mechanisms of IPC such asnamed pipes,Unix domain sockets orCORBA). On the other hand, it is less scalable, as for example the communicating processes must be running on the same machine (of other IPC methods, only Internet domain sockets—not Unix domain sockets—can use acomputer network), and care must be taken to avoid issues if processes sharing memory are running on separate CPUs and the underlying architecture is notcache coherent.
IPC by shared memory is used for example to transfer images between the application and theX server on Unix systems, or inside the IStream object returned by CoMarshalInterThreadInterfaceInStream in the COM libraries underWindows.
Dynamic libraries are generally held in memory once and mapped to multiple processes, and only pages that had to be customized for the individual process (because a symbol resolved differently there) are duplicated, usually with a mechanism known ascopy-on-write that transparently copies the page when a write is attempted, and then lets the write succeed on the private copy.
Compared to multiple address space operating systems,memory sharing -- especially of sharing procedures or pointer-based structures --is simpler insingle address space operating systems.[2]
POSIX provides a standardizedAPI for using shared memory,POSIX Shared Memory. This uses the functionshm_open from sys/mman.h.[3] POSIX interprocess communication (part of the POSIX:XSI Extension) includes the shared-memory functionsshmat,shmctl,shmdt andshmget.[4][5] Unix System V provides an API for shared memory as well. This uses shmget from sys/shm.h. BSD systems provide "anonymous mapped memory" which can be used by several processes.
The shared memory created byshm_open is persistent. It stays in the system until explicitly removed by a process. This has a drawback in that if the process crashes and fails to clean up shared memory it will stay until system shutdown; that limitation is not present in an Android-specific implementation dubbedashmem.[6]
POSIX also provides themmap API for mapping files into memory; a mapping can be shared, allowing the file's contents to be used as shared memory.
Linux distributions based on the 2.6 kernel and later offer /dev/shm as shared memory in the form of aRAM disk, more specifically as a world-writable directory (a directory in which every user of the system can create files) that is stored in memory. Both theRedHat andDebian based distributions include it by default. Support for this type of RAM disk is completely optional within the kernelconfiguration file.[7]
On Windows, one can useCreateFileMapping andMapViewOfFile functions to map a region of a file into memory in multiple processes.[8]
Some C++ libraries provide a portable and object-oriented access to shared memory functionality. For example,Boost contains the Boost.Interprocess C++ Library[9] andQt provides the QSharedMemory class.[10]
For programming languages with POSIX bindings (say, C/C++), shared memory regions can be created and accessed by calling the functions provided by the operating system. Other programming languages may have their own ways of using these operating facilities for similar effect. For example,PHP provides anAPI to create shared memory, similar toPOSIX functions.[11]
The POSIX interprocess communication (IPC) is part of the POSIX:XSI Extension and has its origin in Unix System V interprocess communication.