Module: IO::Memory::Generic
Overview
Generic implementation of memory-mapped IO using temporary files. This implementation provides maximum compatibility across platforms by using Ruby’s built-in Tempfile class and file descriptor mapping. The temporary files are unlinked immediately after creation to behave like anonymous memory objects.
Class Method Summary collapse
-
.supported? ⇒ Boolean
Check if the generic temporary file implementation is supported on this system.
Instance Method Summary collapse
-
#new(size) ⇒ Object
Create a new memory-mapped buffer using a temporary file.
-
#with(size, &block) ⇒ Object
Create a memory-mapped buffer and yield it to a block.
Class Method Details
.supported? ⇒ Boolean
Check if the generic temporary file implementation is supported on this system. This implementation always returns true as it uses standard Ruby temporary files which are available on all platforms. It serves as a fallback when platform-specific implementations like Linux memfd_create or POSIX shm_open are not available.
82 83 84 |
# File 'lib/io/memory/generic.rb', line 82 def self.supported? true end |
Instance Method Details
#new(size) ⇒ Object
Create a new memory-mapped buffer using a temporary file. The temporary file is immediately unlinked to behave like anonymous memory, existing only in the filesystem cache.
91 92 93 |
# File 'lib/io/memory/generic.rb', line 91 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.
102 103 104 105 106 107 108 109 |
# File 'lib/io/memory/generic.rb', line 102 def with(size, &block) handle = new(size) begin yield handle ensure handle.close end end |