Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
IO#advise
static VALUE
rb_io_advise(int argc, VALUE *argv, VALUE io)
{
VALUE advice, offset, len;
rb_off_t off, l;
rb_io_t *fptr;
rb_scan_args(argc, argv, "12", &advice, &offset, &len);
advice_arg_check(advice);
io = GetWriteIO(io);
GetOpenFile(io, fptr);
off = NIL_P(offset) ? 0 : NUM2OFFT(offset);
l = NIL_P(len) ? 0 : NUM2OFFT(len);
#ifdef HAVE_POSIX_FADVISE
return do_io_advise(fptr, advice, off, l);
#else
((void)off, (void)l); /* Ignore all hint */
return Qnil;
#endif
}
Invokes Posix system call posix_fadvise(2), which announces an intention to access data from the current file in a particular manner.
The arguments and results are platform-dependent.
The relevant data is specified by:
-
offset: The offset of the first byte of data. -
len: The number of bytes to be accessed; iflenis zero, or is larger than the number of bytes remaining, all remaining bytes will be accessed.
Argument advice is one of the following symbols:
-
:normal: The application has no advice to give about its access pattern for the specified data. If no advice is given for an open file, this is the default assumption. -
:sequential: The application expects to access the specified data sequentially (with lower offsets read before higher ones). -
:random: The specified data will be accessed in random order. -
:noreuse: The specified data will be accessed only once. -
:willneed: The specified data will be accessed in the near future. -
:dontneed: The specified data will not be accessed in the near future.
Not implemented on all platforms.