Bytevectors

Bytevectors are a representation for binary data, based on SRFI 74 [32]. The primary motivation for including them in R6RS was to enable binary I/O. Positions in bytevectors always refer to certain bytes or octets. However, the operations of the (rnrs bytevectors (6)) library provide access to binary data in various byte-aligned formats, such as signed and unsigned integers of various widths, IEEE floating-point representations, and textual encodings. This differs notably from representations for binary data as homogeneous vectors of numbers. In settings related to I/O, an application often needs to access different kinds of entities from a single binary block. Providing operations for them on a single datatype considerably reduces both programming effort and library size.

Bytevectors can also be used to encode sequences of unboxed number objects. Unencapsulated use of bytevectors for this purpose may lead to aliasing, which may reduce the effectiveness of compiler optimizations. However, sealedness and opacity of records, together with bytevectors, make it possible to construct a portable implementation for new data types that provides fast and memory-efficient arrays of homogeneous numerical data.