]> gitweb.factorcode.org Git - factor.git/blob - basis/io/buffers/buffers-docs.factor
Fix permission bits
[factor.git] / basis / io / buffers / buffers-docs.factor
1 USING: help.markup help.syntax byte-arrays alien destructors ;
2 IN: io.buffers
3
4 ARTICLE: "buffers" "Locked I/O buffers"
5 "I/O buffers are first-in-first-out queues of bytes."
6 $nl
7 "Buffers are backed by manually allocated storage that does not get moved by the garbage collector; they are also low-level and sacrifice error checking for efficiency."
8 $nl
9 "Buffers are used to implement native I/O backends."
10 $nl
11 "Buffer words are found in the " { $vocab-link "io.buffers" } " vocabulary."
12 { $subsection buffer }
13 { $subsection <buffer> }
14 "Buffers must be manually deallocated by calling " { $link dispose } "."
15 $nl
16 "Buffer operations:"
17 { $subsection buffer-reset }
18 { $subsection buffer-length }
19 { $subsection buffer-empty? }
20 { $subsection buffer-capacity }
21 { $subsection buffer@ }
22 "Reading from the buffer:"
23 { $subsection buffer-peek }
24 { $subsection buffer-pop }
25 { $subsection buffer-read }
26 "Writing to the buffer:"
27 { $subsection byte>buffer }
28 { $subsection >buffer }
29 { $subsection n>buffer } ;
30
31 ABOUT: "buffers"
32
33 HELP: buffer
34 { $class-description "The class of I/O buffers, which resemble FIFO queues, but are optimized for holding bytes, are have underlying storage allocated at a fixed address. Buffers must be de-allocated manually."
35 $nl
36 "Buffers have two internal pointers:"
37 { $list
38     { { $snippet "fill" } " - the fill pointer, a write index where new data is added" }
39     { { $snippet "pos" } " - the position, a read index where data is consumed" }
40 } } ;
41
42 HELP: <buffer>
43 { $values { "n" "a non-negative integer" } { "buffer" buffer } }
44 { $description "Creates a buffer with an initial capacity of " { $snippet "n" } " bytes." } ;
45
46 HELP: buffer-reset
47 { $values { "n" "a non-negative integer" } { "buffer" buffer } }
48 { $description "Resets the fill pointer to 0 and the position to " { $snippet "count" } "." } ;
49
50 HELP: buffer-consume
51 { $values { "n" "a non-negative integer" } { "buffer" buffer } }
52 { $description "Moves the position forward by " { $snippet "n" } " bytes. If it exceeds the fill pointer, both are reset to 0." } ;
53
54 HELP: buffer@
55 { $values { "buffer" buffer } { "alien" alien } }
56 { $description "Outputs the memory address of the current buffer position." } ;
57
58 HELP: buffer-end
59 { $values { "buffer" buffer } { "alien" alien } }
60 { $description "Outputs the memory address of the current fill-pointer." } ;
61
62 HELP: buffer-read
63 { $values { "n" "a non-negative integer" } { "buffer" buffer } { "byte-array" byte-array } }
64 { $description "Collects a byte array of " { $snippet "n" } " bytes starting from the buffer's current position, and advances the position accordingly. If there are less than " { $snippet "n" } " bytes available, the output is truncated." } ;
65
66 HELP: buffer-length
67 { $values { "buffer" buffer } { "n" "a non-negative integer" } }
68 { $description "Outputs the number of unconsumed bytes in the buffer." } ;
69
70 HELP: buffer-capacity
71 { $values { "buffer" buffer } { "n" "a non-negative integer" } }
72 { $description "Outputs the buffer's maximum capacity before growing." } ;
73
74 HELP: buffer-empty?
75 { $values { "buffer" buffer } { "?" "a boolean" } }
76 { $description "Tests if the buffer contains no more data to be read." } ;
77
78 HELP: >buffer
79 { $values { "byte-array" byte-array } { "buffer" buffer } }
80 { $description "Copies a byte array to the buffer's fill pointer, and advances it accordingly." }
81 { $warning "This word will corrupt memory if the byte array is larger than the space available in the buffer." } ;
82
83 HELP: byte>buffer
84 { $values { "byte" "a byte" } { "buffer" buffer } }
85 { $description "Appends a single byte to a buffer." }
86 { $warning "This word will corrupt memory if the buffer is full." } ;
87
88 HELP: n>buffer
89 { $values { "n" "a non-negative integer" } { "buffer" buffer } }
90 { $description "Advances the fill pointer by " { $snippet "n" } " bytes." }
91 { $warning "This word will leave the buffer in an invalid state if it does not have " { $snippet "n" } " bytes available." } ;
92
93 HELP: buffer-peek
94 { $values { "buffer" buffer } { "byte" "a byte" } }
95 { $description "Outputs the byte at the buffer position." } ;
96
97 HELP: buffer-pop
98 { $values { "buffer" buffer } { "byte" "a byte" } }
99 { $description "Outputs the byte at the buffer position and advances the position." } ;