D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
IO
/
Buffer
/
Filename :
cdesc-Buffer.ri
back
Copy
U:RDoc::NormalClass[iI"Buffer:ETI"IO::Buffer;TI"Object;To:RDoc::Markup::Document:@parts[o;;[o:RDoc::Markup::Paragraph;[I"LIO::Buffer is a efficient zero-copy buffer for input/output. There are ;TI"typical use cases:;To:RDoc::Markup::BlankLine o:RDoc::Markup::List: @type:BULLET:@items[ o:RDoc::Markup::ListItem:@label0;[o; ;[I"KCreate an empty buffer with ::new, fill it with buffer using #copy or ;TI"O#set_value, #set_string, get buffer with #get_string or write it directly ;TI"to some file with #write.;To;;0;[o; ;[I"MCreate a buffer mapped to some string with ::for, then it could be used ;TI"Pboth for reading with #get_string or #get_value, and writing (writing will ;TI"$change the source string, too).;To;;0;[o; ;[I"OCreate a buffer mapped to some file with ::map, then it could be used for ;TI"-reading and writing the underlying file.;To;;0;[o; ;[I"KCreate a string of a fixed size with ::string, then #read into it, or ;TI" modify it using #set_value.;T@o; ;[I"QInteraction with string and file memory is performed by efficient low-level ;TI" C mechanisms like `memcpy`.;T@o; ;[I"UThe class is meant to be an utility for implementing more high-level mechanisms ;TI"Tlike Fiber::Scheduler#io_read and Fiber::Scheduler#io_write and parsing binary ;TI"protocols.;T@S:RDoc::Markup::Heading: leveli: textI"Examples of Usage;T@o; ;[I"Empty buffer:;T@o:RDoc::Markup::Verbatim;[I">buffer = IO::Buffer.new(8) # create empty 8-byte buffer ;TI" # => ;TI"3# #<IO::Buffer 0x0000555f5d1a5c50+8 INTERNAL> ;TI"# ... ;TI"buffer ;TI" # => ;TI"2# <IO::Buffer 0x0000555f5d156ab0+8 INTERNAL> ;TI"+# 0x00000000 00 00 00 00 00 00 00 00 ;TI"abuffer.set_string('test', 2) # put there bytes of the "test" string, starting from offset 2 ;TI"# => 4 ;TI")buffer.get_string # get the result ;TI"!# => "\x00\x00test\x00\x00" ;T:@format0o; ;[I"\Buffer from string:;T@o;;[I"string = 'data' ;TI"(IO::Buffer.for(string) do |buffer| ;TI" buffer ;TI" # => ;TI"2 # #<IO::Buffer 0x00007f3f02be9b18+4 SLICE> ;TI"J # 0x00000000 64 61 74 61 data ;TI" ;TI"C buffer.get_string(2) # read content starting from offset 2 ;TI" # => "ta" ;TI"K buffer.set_string('---', 1) # write content, starting from offset 1 ;TI" # => 3 ;TI" buffer ;TI" # => ;TI"2 # #<IO::Buffer 0x00007f3f02be9b18+4 SLICE> ;TI"J # 0x00000000 64 2d 2d 2d d--- ;TI". string # original string changed, too ;TI" # => "d---" ;TI" end ;T;0o; ;[I"\Buffer from file:;T@o;;[I")File.write('test.txt', 'test data') ;TI"# => 9 ;TI"4buffer = IO::Buffer.map(File.open('test.txt')) ;TI" # => ;TI";# #<IO::Buffer 0x00007f3f0768c000+9 MAPPED IMMUTABLE> ;TI"# ... ;TI"Dbuffer.get_string(5, 2) # read 2 bytes, starting from offset 5 ;TI"# => "da" ;TI"4buffer.set_string('---', 1) # attempt to write ;TI"J# in `set_string': Buffer is not writable! (IO::Buffer::AccessError) ;TI" ;TI"-# To create writable file-mapped buffer ;TI"@# Open file for read-write, pass size, offset, and flags=0 ;TI"Cbuffer = IO::Buffer.map(File.open('test.txt', 'r+'), 9, 0, 0) ;TI"!buffer.set_string('---', 1) ;TI"# => 3 -- bytes written ;TI"File.read('test.txt') ;TI"# => "t--- data" ;T;0o; ;[I"O<b>The class is experimental and the interface is subject to change, this ;TI"Jis especially true of file mappings which may be removed entirely in ;TI"the future.</b>;T: @fileI"io_buffer.c;T:0@omit_headings_from_table_of_contents_below0;0;0[ [U:RDoc::Constant[i I"PAGE_SIZE;TI"IO::Buffer::PAGE_SIZE;T:public0o;;[o; ;[I"XThe operating system page size. Used for efficient page-aligned memory allocations.;T@;@~;0@~@cRDoc::NormalClass0U;[i I"DEFAULT_SIZE;TI"IO::Buffer::DEFAULT_SIZE;T;0o;;[o; ;[I"MThe default buffer size, typically a (small) multiple of the PAGE_SIZE. ;TI"LCan be explicitly specified by setting the RUBY_IO_BUFFER_DEFAULT_SIZE ;TI"environment variable.;T@;@~;0@~@@�0U;[i I" EXTERNAL;TI"IO::Buffer::EXTERNAL;T;0o;;[o; ;[I"gIndicates that the memory in the buffer is owned by someone else. See #external? for more details.;T@;@~;0@~@@�0U;[i I" INTERNAL;TI"IO::Buffer::INTERNAL;T;0o;;[o; ;[I"eIndicates that the memory in the buffer is owned by the buffer. See #internal? for more details.;T@;@~;0@~@@�0U;[i I"MAPPED;TI"IO::Buffer::MAPPED;T;0o;;[o; ;[I"nIndicates that the memory in the buffer is mapped by the operating system. See #mapped? for more details.;T@;@~;0@~@@�0U;[i I"SHARED;TI"IO::Buffer::SHARED;T;0o;;[o; ;[I"�Indicates that the memory in the buffer is also mapped such that it can be shared with other processes. See #shared? for more details.;T@;@~;0@~@@�0U;[i I"LOCKED;TI"IO::Buffer::LOCKED;T;0o;;[o; ;[I"|Indicates that the memory in the buffer is locked and cannot be resized or freed. See #locked? and #locked for more details.;T@;@~;0@~@@�0U;[i I"PRIVATE;TI"IO::Buffer::PRIVATE;T;0o;;[o; ;[I"�Indicates that the memory in the buffer is mapped privately and changes won't be replicated to the underlying file. See #private? for more details.;T@;@~;0@~@@�0U;[i I" READONLY;TI"IO::Buffer::READONLY;T;0o;;[o; ;[I"{Indicates that the memory in the buffer is read only, and attempts to modify it will fail. See #readonly? for more details.;T@;@~;0@~@@�0U;[i I"LITTLE_ENDIAN;TI"IO::Buffer::LITTLE_ENDIAN;T;0o;;[o; ;[I"{Refers to little endian byte order, where the least significant byte is stored first. See #get_value for more details.;T@;@~;0@~@@�0U;[i I"BIG_ENDIAN;TI"IO::Buffer::BIG_ENDIAN;T;0o;;[o; ;[I"wRefers to big endian byte order, where the most significant byte is stored first. See #get_value for more details.;T@;@~;0@~@@�0U;[i I"HOST_ENDIAN;TI"IO::Buffer::HOST_ENDIAN;T;0o;;[o; ;[I"SRefers to the byte order of the host machine. See #get_value for more details.;T@;@~;0@~@@�0U;[i I"NETWORK_ENDIAN;TI"IO::Buffer::NETWORK_ENDIAN;T;0o;;[o; ;[I"dRefers to network byte order, which is the same as big endian. See #get_value for more details.;T@;@~;0@~@@�0[[I"Comparable;To;;[ ;@~;0I"io_buffer.c;T[[I" class;T[[;[ [I"for;T@�[I"map;T@�[I"new;T@�[I"size_of;T@�[I"string;T@�[:protected[ [:private[ [I" instance;T[[;[1[I"&;T@�[I"<=>;T@�[I"^;T@�[I"|;T@�[I"~;T@�[I" and!;T@�[I" clear;T@�[I" copy;T@�[I" each;T@�[I"each_byte;T@�[I"empty?;T@�[I"external?;T@�[I" free;T@�[I"get_string;T@�[I"get_value;T@�[I"get_values;T@�[I"hexdump;T@�[I"initialize_copy;T@�[I"inspect;T@�[I"internal?;T@�[I"locked;T@�[I"locked?;T@�[I"mapped?;T@�[I" not!;T@�[I" null?;T@�[I"or!;T@�[I" pread;T@�[I" private?;T@�[I"pwrite;T@�[I" read;T@�[I"readonly?;T@�[I"resize;T@�[I"set_string;T@�[I"set_value;T@�[I"set_values;T@�[I"shared?;T@�[I" size;T@�[I" slice;T@�[I" to_s;T@�[I" transfer;T@�[I"valid?;T@�[I"values;T@�[I" write;T@�[I" xor!;T@�[;[ [;[ [ [U:RDoc::Context::Section[i 0o;;[ ;0;0[I"ext/io/console/console.c;TI"IO;T@�