Skip to content
instance method

IO::Buffer#shared?

shared? → true or false

If the buffer is shared, meaning it references memory that can be shared with other processes (and thus might change without being modified locally).

Example
# Create a test file:
File.write('test.txt', 'test')

# Create a shared mapping from the given file, the file must be opened in
# read-write mode unless we also specify IO::Buffer::READONLY:
buffer = IO::Buffer.map(File.open('test.txt', 'r+'), nil, 0)
# => #<IO::Buffer 0x00007f1bffd5e000+4 EXTERNAL MAPPED SHARED>

# Write to the buffer, which will modify the mapped file:
buffer.set_string('b', 0)
# => 1

# The file itself is modified:
File.read('test.txt')
# => "best"
See also #set_values #size #set_value #slice also in 3.4 · 3.3 · 3.2