Module: IO::Memory::POSIX
Overview
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.
Class Method Summary collapse
-
.supported? ⇒ Boolean
Check if the POSIX shared memory implementation is supported on this system.
Instance Method Summary collapse
-
#new(size) ⇒ Object
Create a new memory-mapped buffer using POSIX shared memory.
-
#with(size, &block) ⇒ Object
Create a memory-mapped buffer and yield it to a block.
Class Method Details
.supported? ⇒ Boolean
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.
135 136 137 |
# File 'lib/io/memory/posix.rb', line 135 def self.supported? Implementation.supported? end |
Instance Method Details
#new(size) ⇒ Object
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.
145 146 147 |
# File 'lib/io/memory/posix.rb', line 145 def new(size) Implementation.create_handle(size) end |
#with(size, &block) ⇒ Object
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.
156 157 158 159 160 161 162 163 |
# File 'lib/io/memory/posix.rb', line 156 def with(size, &block) handle = new(size) begin yield handle ensure handle.close end end |