IO::MemorySourceIOMemoryLinux

module Linux

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.

Nested

Definitions

def self.supported?

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.

Signature

returns Boolean

true if memfd_create is available, false otherwise

Implementation

def self.supported?
	Implementation.supported?
end

def new(size)

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.

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

returns Object

the result of the block execution

Implementation

def with(size, &block)
	handle = new(size)
	begin
		yield handle
	ensure
		handle.close
	end
end