instance method
IO::Buffer#shared?
shared? → true or false
io_buffer.c
View on GitHub ↗
static VALUE
rb_io_buffer_shared_p(VALUE self)
{
struct rb_io_buffer *buffer = NULL;
TypedData_Get_Struct(self, struct rb_io_buffer, &rb_io_buffer_type, buffer);
return RBOOL(buffer->flags & RB_IO_BUFFER_SHARED);
}
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"