IPC::Shm::Simple - Simple data in SysV shared memory segments.
Provides the ability to create a shared segment with or without first knowing what ipckey it will use. Caches shared memory reads in process memory, and defeatably verifies writes by reading the value back and comparing it stringwise.
Can only store string or numeric data.
This module caches the underlying C object, such that the process only has one attachment to the shared segment. However, the Perl objects are not cached, to facilitate timely destruction. There can be many distinct blessed references to the same shared segment. This is made transparent by storing all state information in package lexicals, not upon the object.
Attach to the shared memory segment identified by ipckey, whether it exists already or not.
If a segment must be created, size and permissions may be specified as for the $this->create() call. Otherwise, the class defaults will apply.
$this->create()
Returns blessed reference on success, undef on failure.
Throws an exception on invalid parameters.
The segment will be unlocked even if it was just created.
Attach to the shared memory segment identified by ipckey if it exists.
Called by $this-attach() > and $this-shmat() > when an uncached attachment occurs.
$this-
Must return true, otherwise the attachment is aborted.
Does nothing on its own; this is meant for subclasses to override.
Create a new shared memory segment, with the given ipckey, unless it exists. Can be given IPC_PRIVATE as an ipckey to create an unkeyed segment, which is assumed if no argument is provided.
IPC_PRIVATE
The optional parameters segsize and permissions default to $this->Size() and $this->Mode(), respectively.
$this->Size()
$this->Mode()
The segment will automatically have a writelock in effect.
Attach to an existing shared memory segment by its shmid.
Uncaches the referenced instance, and causes the underlying shared memory segments to be removed from the operating system when DESTROYed.
Returns 1 on success, undef on failure.
Called by $self-DESTROY() > on the last copy of the object.
$self-
Uncaches the referenced instance, and causes the underlying shared memory segments to be detached by the operating system.
If subclasees override this, they must call $self-SUPER::DESTROY() >.
Returns the ipckey assigned by the program at instantiation.
Returns the shmid assigned by the operating system at instantiation.
Returns the permissions flags assigned at instantiation.
Returns the number of bytes currently stored in the share.
Returns the serial number of the current shared memory value.
Returns the total size of the top share segment, in bytes.
Returns the size of data chunk segments, in bytes.
Changes the size of chunk data segments. The share must have only one allocated segment (the top segment) for this call to succeed.
Reports the number of processes connected to the share.
Returns the current shared reference count.
Increments the shared reference counter.
Decrements the shared reference counter.
Returns a scalar reference to the segment cache. Does not guarantee freshness, and the reference can become invalid after the next I/O operation.
Entirely removes the cache entry for the object.
Fetch a previously stored value.
If nothing has been stored yet, '' (the empty string) is returned.
''
Invoked by fetch() when the data has been changed by another process.
fetch()
Stores a string or numeric value in the shared memory segment.
Specifies the time-to-live of cached shared memory reads, in seconds. This only affects the case where the serial number has -not- changed.
Default: 0.
Specifies whether to read-back and compare shared memory writes.
Expensive.
Default: 1.
These methods carry the default values used during instantiation.
Specifies or fetches the permissions for new segments. Default: 0660.
Specifies or fetches the initial size of new shared memory segments. Default: 4096
To do.
To install IPC::Shm::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm IPC::Shm::Simple
CPAN shell
perl -MCPAN -e shell install IPC::Shm::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.