In computer science , shared memory is memory That May be Simultaneously accessed by multiple programs with an intent to Provide Communication Among Them gold 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, eg among its multiple threads , is also referred to as shared memory.
In computer hardware, shared memory refers to a (typically large) block of random access memory (RAM) that can be accessed by several different central processing units (CPUs) in a multiprocessor computer system .
Shared memory systems may use: 
- uniform memory access (UMA): all the processors share the physical memory uniformly;
- non-uniform memory access (NUMA): memory access time depends on the memory location relative to a processor;
- cache-only memory architecture (COMA): the local memories for the processors at each node is used as the main memory.
A shared memory system is relatively easy to program since it has a similar relationship to the other. The issue with shared memory systems is that many CPUs need fast access to memory and will likely cache memory , which has two complications:
- access time degradation: when multiple processors try to access the same memory location it causes contention. Trying to access nearby memory rentals may cause false sharing . Shared memory computers can not scale very well. Most of them have ten or fewer processors;
- lack of data coherence: any one of the two processes, the change needs to be reported, otherwise the processors will be working with incoherent data. Such cache coherence protocols can, when they work well, provide extremely high-performance access to shared information between multiple processors. On the other hand, they can sometimes become overloaded and become bottleneck to performance.
Technologies like crossbar switches , Omega networks , HyperTransport or front-side buses can be used to dampen the bottleneck-effects.
In the case of a Heterogeneous System Architecture (processor architecture that integrates different types of processors, such as CPUs and GPUs , with shared memory), the memory management unit (MMU) of the CPU and the input-output memory management unit (IOMMU) of the GPU have a certain characteristics, like a common address space.
The alternatives to shared memory are distributed memory and distributed shared memory , each having a similar set of issues.
In computer software, shared memory is
- a method of inter-process communication (IPC), ie a way of exchanging data between programs running at the same time. One process will create an area in RAM which other processes can access;
- A method of conserving memory space by directing accesses to what would ordinarily be copies of a piece of data to a single instance instead, by using virtual memory mappings or with explicit support of the program in question. This is most often used for shared libraries and for XIP .
Since both processes are used, this is a very fast way of communication (as opposed to other mechanisms of IPC, such as named pipes , Unix domain sockets or CORBA ). On the other hand, it is less scalable, as for example the communicating processes must be running on the same machine, (and other IPC methods, only Internet domain sockets-not Unix domain sockets-can use a computer network ), and care must be taken to avoid issues if processes sharing memory are running on separate CPUs and the underlying architecture is not cache coherent .
IPC by shared memory is used for example to transfer images between the application and the X server on Unix systems, or inside the IStream object returned by CoMarshalInterThreadInterfaceInStream in the COM libraries under Windows .
Dynamic libraries are Generally Held in memory ounce and mapped to multiple processes, and only pages That Had To Be customized for the individual process (Because a symbol resolved are differently there) are duplicated, usually with a mechanism Known as copy-on-write That Transparently copies the page when a write is attempted, and then lets the write succeed on the private copy.
Support on Unix-like systems
POSIX provides a standardized API for shared memory, POSIX Shared Memory . This uses the function
shm_openfrom sys / mman.h.  POSIX interprocess communication (part of the POSIX: XSI Extension) includes the shared-memory functions
shmget.   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 by
shm_openis persistent. It stays in the system until officially removed by a process. This has a drawback that if the process crashes and fails to clean up it will stay until system shutdown.
POSIX also provides the
mmapAPI for mapping files into memory; a mapping can be shared, allowing the file to be used as shared memory.
Linux distributions based on the kernel and later offer / dev / shm as shared memory in the form of a RAM disk , more specifically a world-writable directory (a directory in which every user of the system can create files) that is stored in memory. Both the RedHat and Debian based distributions include it by default. Support for this type of RAM is completely optional within the kernel configuration file . 
Support on Windows
CreateSharedMemorycan be used to create a shared memory.  Alternatively one can use
MapViewOfFilefunctions to map a area of a file into memory in multiple processes. 
Some C ++ libraries provide a portable and object-oriented access to shared memory functionality. For example, Boost contains Boost.Interprocess C ++ Library.  Qt provides QSharedMemory class. 
Programming language support
There is native support for other C / C ++ besides. For example, PHP provides API to create shared memory, similar to POSIX functions. 
- Distributed memory
- Distributed shared memory
- Shared graphics memory
- Heterogeneous System Architecture
- Global variable
- Execute in place
- Shared register
- Shared snapshot objects
- Jump up^ El-Rewini, Hesham; Abd-El-Barr, Mostafa (2005). Advanced Computer Architecture and Parallel Processing . Wiley-Interscience. pp. 77-80. ISBN 978-0-471-46740-3 .
- Jump up^ Documentation of shm_openfrom the Single Unix Specification
- Jump up^ Robbins, Kay A .; Robbins, Steven (2003). Unix systems programming: communication, concurrency, and threads (2 ed.). Prentice Hall PTR. p. 512. ISBN 978-0-13-042411-2 . Retrieved 2011-05-13 .
The POSIX interprocess communication (IPC) is part of the POSIX: XSI extension and has its origin in Unix System V interprocess communication.
- Jump up^ Shared memory facilityfrom the Single Unix Specification.
- Jump up^ Christoph Rohland; Hugh Dickins; KOSAKI Motohiro. “tmpfs.txt” . kernel.org . Retrieved 2010-03-16 .
- Jump up^ CreateSharedMemory functionfrom Win32-SDK
- Jump up^ Creating Named Shared Memoryfrom MSDN.
- Jump up^ Boost.Interprocess C ++ Library
- Jump up^ QSharedMemory Class Reference
- Jump up^ Shared Memory Functions in PHP-API