class IO::Buffer::Slice

A zero-copy, parent-relative view of an IO::Buffer or another Slice. Create a view with IO::Buffer#slice or IO::Buffer::Slice.new:

buffer = IO::Buffer.new(6)
buffer.set_string("abcdef")
parent = buffer.slice(1, 4)
child = parent.slice(1, 2)
child.source.equal?(parent) # => true
child.get_string            # => "cd"
parent.advance(1)
child.get_string            # => "de"

A slice retains its immediate source and follows that source’s current view. Its range is valid only while every parent is valid and the range fits within its source. Moving the backing allocation does not itself invalidate a slice. Shrinking a parent can invalidate descendants; growing it again can restore their validity.

Slice inherits Buffer’s byte-access interface but does not manage storage. Resizing a slice only changes its extent within its parent’s bounds, and advancing it consumes bytes from the front of its view. Neither operation allocates or releases storage. Slice has no free or transfer method, nor Storage’s predicates such as mapped? or internal?.

Writes modify the source’s bytes and respect its current permissions. Locking a slice protects the backing allocation; locked? reports that shared lock state. Locked or read-only views may still be resized or advanced, but frozen views cannot change their range. Locking does not serialize access to bytes or view metadata.

Duplicating or cloning a Slice copies its view rather than its bytes. Both Slice and Storage are subclasses of IO::Buffer.