IPC::ShareLite(3pm)
๐ IPC::ShareLite โ the manual, but make it make sense ๐
okay bestie, so this is the doc page for IPC::ShareLite, and it lives in the "User Contributed Perl Documentation" section of the manual (that's the 3pm part, iykyk). It's the cute lil lightweight interface to shared memory. Let's go ๐ฆ
โจ NAME โจ
IPC::ShareLite โ a lightweight interface to shared memory. That's it, that's the name, periodt.
๐ธ VERSION ๐ธ
This document describes IPC::ShareLite version 0.17. Not 0.18, not 0.1.7, not vibes. 0.17. ๐
๐ SYNOPSIS ๐
here's the glow-up in action:
use IPC::ShareLite;
my $share = IPC::ShareLite->new(
-key => 1971,
-create => 'yes',
-destroy => 'no'
) or die $!;
$share->store( "This is stored in shared memory" );
my $str = $share->fetch;
slay. you make a share, you put a string in it, you get the string back. icon behavior. โจ
๐ซ DESCRIPTION ๐ซ
So IPC::ShareLite gives you a simple interface to shared memory, which means data can be efficiently communicated between processes. The catch: your operating system has to support SysV IPC (that's shared memory and semaphores) or this whole thing is a no-go. ๐ซ
What it actually does: IPC::ShareLite abstracts the shared memory and semaphore facilities of SysV IPC so you can store arbitrarily large data. The module automatically acquires and removes shared memory segments as needed. Storage and retrieval of data is atomic, and there are locking functions for higher-level synchronization. no cap. ๐ฅ
In many respects this module is similar to IPC::Shareable. However โ and this is the important tea โ โ IPC::ShareLite does not provide a tied interface, does not (automatically) allow the storage of variables, and is written in C for additional speed. it's giving fast. it's giving efficient. ๐
You construct an IPC::ShareLite object by calling its constructor:
my $share = IPC::ShareLite->new(
-key => 1971,
-create => 'yes',
-destroy => 'no'
) or die $!;
Once an instance has been created, data can be written to shared memory by calling the store() method:
$share->store("This is going in shared memory");
Retrieve the data by calling the fetch() method:
my $str = $share->fetch();
The store() and fetch() methods are atomic โ any processes attempting to read or write to the memory are blocked until these calls finish. But sometimes, bestie, you want to perform multiple operations atomically. That's what the advisory locking methods are for. ๐
An exclusive lock is obtained by calling the lock() method:
$share->lock();
Happily ๐ซถ, the lock() method also accepts all of the flags recognized by the flock() system call. So for example, you can obtain a shared lock like this:
$share->lock( LOCK_SH );
Or you can make either type of lock non-blocking:
$share->lock( LOCK_EX|LOCK_NB );
Release the lock by calling the unlock() method:
$share->unlock;
๐ง METHODS ๐ง
๐ "new($key, $create, $destroy, $exclusive, $mode, $flags, $size)"
This is the constructor for IPC::ShareLite. It accepts both the positional and named parameter calling styles. versatile queen. ๐
$keyis an integer value used to associate data between processes. All processes wishing to communicate should use the same$keyvalue.$keymay also be specified as a four character string, in which case it will be converted to an integer value automatically. If$keyis undefined, the shared memory will not be accessible from other processes. ๐$createspecifies whether the shared memory segment should be created if it does not already exist. Acceptable values are1,'yes',0, or'no'.$destroyindicates whether the shared memory segments and semaphores should be removed from the system once the object is destroyed. Acceptable values are1,'yes',0, or'no'.- If
$exclusiveis true, instantiation will fail if the shared memory segment already exists. Acceptable values are1,'yes',0, or'no'. $modespecifies the permissions for the shared memory and semaphores. The default value is0666.$flagsspecifies the exact shared memory and semaphore flags to use. The constantsIPC_CREAT,IPC_EXCL, andIPC_PRIVATEare available for import.$sizespecifies the shared memory segment size, in bytes. The default size is 65,536 bytes, which is fairly portable. Linux, as an example, supports segment sizes of 4 megabytes.
The constructor croaks on error. no soft launch, it just screams. ๐ญ
๐ธ store( $scalar )
This method stores $scalar into shared memory. $scalar may be arbitrarily long. Shared memory segments are acquired and released automatically as the data length changes. The only limits on the amount of data are the system-wide limits on shared memory pages (SHMALL) and segments (SHMMNI) as compiled into the kernel.
The method raises an exception on error.
Note that unlike IPC::Shareable, this module does not automatically allow references to be stored. Serializing all data is expensive, and is not always necessary. If you need to store a reference, you should employ the Storable module yourself. For example:
use Storable qw( freeze thaw );
...
$hash = { red => 1, white => 1, blue => 1 };
$share->store( freeze( $hash ) );
...
$hash = thaw( $share->fetch );
๐ "fetch"
This method returns the data that was previously stored in shared memory. The empty string is returned if no data was previously stored.
The method raises an exception on error.
๐ lock( $type )
Obtains a lock on the shared memory. $type specifies the type of lock to acquire. If $type is not specified, an exclusive read/write lock is obtained. Acceptable values for $type are the same as for the flock() system call. The method returns true on success, and undef on error. For non-blocking calls (see below), the method returns 0 if it would have blocked.
Obtain an exclusive lock like this:
$share->lock( LOCK_EX ); # same as default
Only one process can hold an exclusive lock on the shared memory at a given time.
Obtain a shared lock this this:
$share->lock( LOCK_SH );
Multiple processes can hold a shared lock at a given time. If a process attempts to obtain an exclusive lock while one or more processes hold shared locks, it will be blocked until they have all finished.
Either of the locks may be specified as non-blocking:
$share->lock( LOCK_EX|LOCK_NB );
$share->lock( LOCK_SH|LOCK_NB );
A non-blocking lock request will return 0 if it would have had to wait to obtain the lock.
Note that these locks are advisory (just likeflock), meaning that all cooperating processes must coordinate their accesses to shared memory using these calls in order for locking to work. See theflock()call for details. ๐
Locks are inherited through forks, which means that two processes actually can possess an exclusive lock at the same time. Don't do that. ๐
The constants LOCK_EX, LOCK_SH, LOCK_NB, and LOCK_UN are available for import:
use IPC::ShareLite qw( :lock );
Or, just use the flock constants available in the Fcntl module.
๐ "unlock"
Releases any locks. This is actually equivalent to:
$share->lock( LOCK_UN );
The method returns true on success and undef on error.
โญ "version"
Each share has a version number that increments monotonically for each write to the share. When the share is initally created its version number will be 1.
my $num_writes = $share->version;
๐ "key"
Get a share's key.
my $key = $share->key;
โจ "create"
Get a share's create flag.
๐ "exclusive"
Get a share's exclusive flag.
๐ฉ "flags"
Get a share's flag.
๐ ๏ธ "mode"
Get a share's mode.
๐ "size"
Get a share's segment size.
๐งฎ "num_segments"
Get the number of segments in a share. The memory usage of a share can be approximated like this:
my $usage = $share->size * $share->num_segments;
$usage will be the memory usage rounded up to the next segment boundary.
๐ฅ "destroy"
Get or set the share's destroy flag.
โก PERFORMANCE โก
For a rough idea of the performance you can expect, here are some benchmarks. The tests were performed using the Benchmark module on a Cyrix PR166+ running RedHat Linux 5.2 with the 2.0.36 kernel, perl 5.005_02 using perl's malloc, and the default shared memory segment size. Each test was run 5000 times. ๐ฐ๏ธ (yes, this is vintage, that's the vibe)
DATA SIZE (bytes) TIME (seconds) Op/Sec
store 16384 2 2500
fetch 16384 2 2500
store 32768 3 1666
fetch 32768 3 1666
store 65536 6 833
fetch 65536 5 1000
store 131072 12 416
fetch 131072 12 416
store 262144 28 178
fetch 262144 27 185
store 524288 63 79
fetch 524288 61 81
Most of the time appears to be due to memory copying. Suggestions for speed improvements are welcome. ๐ซถ (they're literally asking, bestie, give them your ideas)
๐ PORTABILITY ๐
The module should compile on any system with SysV IPC and an ANSI C compiler, and should compile cleanly with the -pedantic and -Wall flags.
The module has been tested under Solaris, FreeBSD, and Linux. Testing on other platforms is needed. ๐ฃ
If you encounter a compilation error due to the definition of the semun union, edit the top of sharestuff.c and undefine the semun definition. And then please tell me about it. ๐
I've heard rumors that a SysV IPC interface has been constructed for Win32 systems. Support for it may be added to this module.
IPC::ShareLite does not understand the shared memory data format used by IPC::Shareable. they are not compatible, do not mix them, do not pass go. ๐
๐ AUTHOR ๐
Copyright 1998-2002, Maurice Aubrey <maurice@hevanet.com>. All rights reserved.
This release by Andy Armstrong <andy@hexten.net>.
This module is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
๐ CREDITS ๐
Special thanks to Benjamin Sugars for developing the IPC::Shareable module. ๐ซถ
See the Changes file for other contributors.
๐ฆ SEE ALSO ๐ฆ
IPC::Shareable, ipc(2), shmget(2), semget(2), perl.
and that's the whole page, bestie!! ๐ this was IPC::ShareLite(3pm), generated by perl v5.42.3 back on 2026-08-19, and honestly? iconic of it. go forth and share your memory. slay. ๐
โจ๐๐ฆ
๐ฆ where this page comes from
- ubuntu stonking: libipc-sharelite-perl 0.17-5build5 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms