1 USING: kernel help.markup help.syntax ;
4 ARTICLE: "byte-arrays" "Byte arrays"
5 "Byte arrays are fixed-size mutable sequences (" { $link "sequence-protocol" } ") whose elements are integers in the range 0-255, inclusive. Each element only uses one byte of storage, hence the name. The literal syntax is covered in " { $link "syntax-byte-arrays" } "."
7 "Byte array words are in the " { $vocab-link "byte-arrays" } " vocabulary."
9 "Byte arrays play a special role in the C library interface; they can be used to pass binary data back and forth between Factor and C. See " { $link "c-pointers" } "."
11 "Byte arrays form a class of objects."
16 "There are several ways to construct byte arrays."
25 "Resizing byte-arrays:"
26 { $subsections resize-byte-array } ;
31 { $description "The class of byte arrays. See " { $link "syntax-byte-arrays" } " for syntax and " { $link "byte-arrays" } " for general information." } ;
33 HELP: <byte-array> ( n -- byte-array )
34 { $values { "n" "a non-negative integer" } { "byte-array" "a new byte array" } }
35 { $description "Creates a new byte array holding " { $snippet "n" } " bytes." } ;
38 { $values { "n" "a non-negative integer" } { "byte-array" "a new byte array" } }
39 { $description "Creates a new byte array with unspecified contents of length " { $snippet "n" } " bytes." } ;
42 { $values { "seq" "a sequence" } { "byte-array" byte-array } }
44 "Outputs a freshly-allocated byte array whose elements have the same signed byte values as a given sequence." }
45 { $errors "Throws an error if the sequence contains elements other than integers." } ;
50 { "byte-array" byte-array } }
51 { $description "Creates a new byte-array with one element." } ;
55 { "x" object } { "y" object }
56 { "byte-array" byte-array } }
57 { $description "Creates a new byte-array with two elements." } ;
61 { "x" object } { "y" object } { "z" object }
62 { "byte-array" byte-array } }
63 { $description "Creates a new byte-array with three element." } ;
67 { "w" object } { "x" object } { "y" object } { "z" object }
68 { "byte-array" byte-array } }
69 { $description "Creates a new byte-array with four elements." } ;
71 { 1byte-array 2byte-array 3byte-array 4byte-array } related-words
73 HELP: resize-byte-array ( n byte-array -- newbyte-array )
74 { $values { "n" "a non-negative integer" } { "byte-array" byte-array }
75 { "newbyte-array" byte-array } }
76 { $description "Creates a new byte-array of n elements. The contents of the existing byte-array are copied into the new byte-array; if the new byte-array is shorter, only an initial segment is copied, and if the new byte-array is longer the remaining space is filled in with 0." } ;