Module: IO::Memory::Linux
Overview
Linux-specific implementation of memory-mapped IO using memfd_create. This implementation provides the most efficient memory mapping on Linux by using the memfd_create system call to create anonymous memory objects that exist only in memory without being backed by any filesystem.
Class Method Summary collapse
-
.supported? ⇒ Boolean
Check if the Linux memfd_create implementation is supported on this system.
Instance Method Summary collapse
-
#new(size) ⇒ Object
Create a new memory-mapped buffer using Linux memfd_create.
-
#with(size, &block) ⇒ Object
Create a memory-mapped buffer and yield it to a block.
Class Method Details
.supported? ⇒ Boolean
Check if the Linux memfd_create implementation is supported on this system. This implementation uses the memfd_create() system call available on Linux 3.17+ and provides the most efficient memory mapping by creating anonymous memory objects.
121 122 123 |
# File 'lib/io/memory/linux.rb', line 121 def self.supported? Implementation.supported? end |
Instance Method Details
#new(size) ⇒ Object
Create a new memory-mapped buffer using Linux memfd_create. This creates an anonymous memory object that exists only in memory without being backed by any filesystem.
131 132 133 |
# File 'lib/io/memory/linux.rb', line 131 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.
142 143 144 145 146 147 148 149 |
# File 'lib/io/memory/linux.rb', line 142 def with(size, &block) handle = new(size) begin yield handle ensure handle.close end end |