Locked I/O buffers
Factor handbook » The language » Collections

Prev:Directed graph utilities


I/O buffers are first-in-first-out queues of bytes.

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.

Buffers are used to implement native I/O backends.

Buffer words are found in the io.buffers vocabulary.
buffer

<buffer> ( n -- buffer )


Buffers must be manually deallocated by calling dispose.

Buffer operations:
buffer-reset ( n: fixnum buffer: buffer -- )

buffer-length ( buffer: buffer -- n )

buffer-empty? ( buffer: buffer -- ? )

buffer-capacity ( buffer: buffer -- n )

buffer@ ( buffer: buffer -- alien )


Reading from the buffer:
buffer-peek ( buffer: buffer -- byte )

buffer-pop ( buffer: buffer -- byte )

buffer-read ( n: fixnum buffer: buffer -- byte-array )

buffer-read-unsafe ( n: fixnum buffer: buffer -- n ptr )

buffer-read-until ( seps buffer: buffer -- byte-array sep/f )


Writing to the buffer:
buffer-write1 ( byte: fixnum buffer: buffer -- )

buffer-write ( c-ptr n buffer: buffer -- )

buffer+ ( n: fixnum buffer: buffer -- )