module POSIX
POSIX implementation of memory-mapped IO using shm_open. This implementation provides efficient memory mapping on POSIX-compliant systems (macOS, BSD, etc.) by using the shm_open system call to create shared memory objects. These objects can be shared between processes and provide zero-copy memory operations.
Nested
Definitions
def self.supported?
Check if the POSIX shared memory implementation is supported on this system. This implementation uses shm_open() and is available on POSIX-compliant systems like macOS, BSD, and some Linux configurations with shared memory support.
Signature
-
returns
Boolean
true if POSIX shared memory is available, false otherwise
Implementation
def self.supported?
Implementation.supported?
end
def new(size)
Create a new memory-mapped buffer using POSIX shared memory. This creates a shared memory object using shm_open that can be shared between processes and provides zero-copy operations.
Signature
-
parameter
size
Integer
size of the memory buffer in bytes
-
returns
Object
a handle object that provides access to the memory buffer
Implementation
def new(size)
Implementation.create_handle(size)
end
def with(size, &block)
Create a memory-mapped buffer and yield it to a block. The buffer is automatically cleaned up when the block exits, regardless of whether an exception is raised.
Signature
-
parameter
size
Integer
size of the memory buffer in bytes
-
yields
{|handle| ...}
-
parameter
handle
Object
the handle to the memory buffer with access to IO and mapping operations
-
parameter
-
returns
Object
the result of the block execution
Implementation
def with(size, &block)
handle = new(size)
begin
yield handle
ensure
handle.close
end
end