1 USING: help io-internals ;
4 { $class-description "The class of I/O buffers, which are allocated in the system malloc arena, and thus have a fixed address, unlike garbage-collected heap objects which are moved around. Buffers must be de-allocated manually."
6 "Buffers have two internal pointers:"
8 { "the fill pointer -- a write index where new data is added; accessor: " { $link buffer-fill } }
9 { "the position -- a read index where data is consumed; accessor: " { $link buffer-pos } }
13 { $values { "n" "a non-negative integer" } { "buffer" "a buffer" } }
14 { $description "Creates a buffer with an initial capacity of " { $snippet "n" } " bytes." } ;
17 { $values { "buffer" "a buffer" } }
18 { $description "De-allocates a buffer's underlying storage. The buffer may not be used after being freed." }
19 { $warning "You " { $emphasis "must" } " free a buffer using this word, before letting the GC collect the buffer tuple instance." } ;
22 { $values { "buffer" "a buffer" } { "string" "a string" } }
23 { $description "Collects the entire contents of the buffer into a string." } ;
26 { $values { "n" "a non-negative integer" } { "buffer" "a buffer" } }
27 { $description "Resets the fill pointer to 0 and the position to " { $snippet "count" } "." } ;
30 { $values { "n" "a non-negative integer" } { "buffer" "a buffer" } }
31 { $description "Moves the position forward by " { $snippet "n" } " bytes. If it exceeds the fill pointer, both are reset to 0." } ;
34 { $values { "buffer" "a buffer" } { "n" "a non-negative integer" } }
35 { $description "Outputs the memory address of the current buffer position." } ;
38 { $values { "buffer" "a buffer" } { "n" "a non-negative integer" } }
39 { $description "Outputs the memory address of the current fill-pointer." } ;
42 { $values { "n" "a non-negative integer" } { "buffer" "a buffer" } }
43 { $description "Outputs a string of the first " { $snippet "n" } " characters at the buffer's current position. If there are less than " { $snippet "n" } " characters available, the output is truncated." }
44 { $see-also buffer> } ;
47 { $values { "n" "a non-negative integer" } { "buffer" "a buffer" } { "string" "a string" } }
48 { $description "Collects a string of " { $snippet "n" } " characters starting from the buffer's current position, and advances the position accordingly. If there are less than " { $snippet "n" } " characters available, the output is truncated." } ;
51 { $values { "buffer" "a buffer" } { "string" "a string" } }
52 { $description "Collects the contents of the buffer into a string, and resets the position and fill pointer to 0." } ;
55 { $values { "buffer" "a buffer" } { "n" "a non-negative integer" } }
56 { $description "Outputs the number of unconsumed bytes in the buffer." } ;
59 { $values { "buffer" "a buffer" } { "n" "a non-negative integer" } }
60 { $description "Outputs the buffer's maximum capacity before growing." } ;
63 { $values { "buffer" "a buffer" } { "?" "a boolean" } }
64 { $description "Tests if the buffer contains no more data to be read." } ;
67 { $values { "n" "a non-negative integer" } { "buffer" "a buffer" } }
68 { $description "Grows a buffer to fit " { $snippet "n" } " bytes of data." } ;
71 { $values { "n" "a non-negative integer" } { "buffer" "a buffer" } }
72 { $description "Grows the buffer, if possible, so it can accomodate " { $snippet "n" } " bytes." }
73 { $warning "I/O system implementations should call this word or one of the other words that calls this word, at the beginning of an I/O transaction, when the buffer is empty. Buffers cannot be resized if they contain data; one of the requirements of a buffer is to remain fixed in memory while I/O operations are in progress." }
74 { $errors "Throws an error if the buffer contains unread data, and the new data does not fit." } ;
77 { $values { "string" "a string" } { "buffer" "a buffer" } }
78 { $description "Copies a string to the buffer's fill pointer, and advances it accordingly." } ;
81 { $values { "ch" "a character" } { "buffer" "a buffer" } }
82 { $description "Appends a single byte to a buffer." } ;
85 { $values { "buffer" "a buffer" } { "n" "a non-negative integer" } }
86 { $description "Outputs the address pointing to the end of the buffer." } ;
89 { $values { "n" "a non-negative integer" } { "buffer" "a buffer" } }
90 { $description "Advances the fill pointer by " { $snippet "n" } " bytes." }
91 { $errors "Throws an error if the buffer does not contain " { $snippet "n" } " bytes of data." } ;
94 { $values { "buffer" "a buffer" } { "ch" "a character" } }
95 { $description "Outputs the byte at the buffer position." }
96 { $see-also buffer-pop } ;
99 { $values { "buffer" "a buffer" } { "ch" "a character" } }
100 { $description "Outputs the byte at the buffer position and advances the position." } ;