Documentation ¶
Overview ¶
Shared memory is an inter-process communication mechanism that allows for multiple, independent processes to access and modify the same portion of system memory for the purpose of sharing data between them. This library implements a Golang wrapper around the original implementation of this which is present on almost all *NIX systems that implement portions of the UNIX System V feature set.
The use of the calls implemented by this library has largely been supplanted by POSIX shared memory (http://man7.org/linux/man-pages/man7/shm_overview.7.html) and the mmap() system call, but there are some use cases that still require this particular approach to shared memory management. One notable example is the MIT-SHM X Server extension (https://www.x.org/releases/X11R7.7/doc/xextproto/shm.html) which expects SysV shared memory semantics.
Index ¶
- Constants
- func DestroySegment(id int) error
- type Segment
- func (self *Segment) Attach() (unsafe.Pointer, error)
- func (self *Segment) Destroy() error
- func (self *Segment) Detach(addr unsafe.Pointer) error
- func (self *Segment) Position() int64
- func (self *Segment) Read(p []byte) (n int, err error)
- func (self *Segment) ReadChunk(length int64, start int64) ([]byte, error)
- func (self *Segment) Reset()
- func (self *Segment) Seek(offset int64, whence int) (int64, error)
- func (self *Segment) Write(p []byte) (n int, err error)
- type SharedMemoryFlags
Constants ¶
const ( IpcNone = 0 IpcCreate SharedMemoryFlags = C.IPC_CREAT IpcExclusive = C.IPC_EXCL HugePages = C.SHM_HUGETLB NoReserve = C.SHM_NORESERVE )
const Version = `0.0.4`
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Segment ¶
A native representation of a SysV shared memory segment
func Create ¶
Create a new shared memory segment with the given size (in bytes). The system will automatically round the size up to the nearest memory page boundary (typically 4KB).
func Open ¶
Open an existing shared memory segment located at the given ID. This ID is returned in the struct that is populated by Create(), or by the shmget() system call.
func OpenSegment ¶
Creates a shared memory segment of a given size, and also allows for the specification of creation flags supported by the shmget() call, as well as specifying permissions.
func (*Segment) Attach ¶
Attaches the segment to the current processes resident memory. The pointer that is returned is the actual memory address of the shared memory segment for use with third party libraries that can directly read from memory.
func (*Segment) Reset ¶
func (self *Segment) Reset()
Resets the internal offset counter for this segment, allowing subsequent calls to Read() or Write() to start from the beginning.
type SharedMemoryFlags ¶
type SharedMemoryFlags int