FunctionPackage: exclToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
Unrevised from 10.0 to 10.1.
10.0 version

make-buffer-input-stream

Arguments: buffer &optional start end external-format

Returns a buffer-input-simple-stream. buffer may be a simple-vector, or it can have a fill-pointer. buffer can also be an aligned pointer, as described below. start defaults to 0, and end defaults to nil, in which case the current length of buffer is used as the end. The external-format argument should be the name of an external-format, or :default will cause it to be looked up in the locale.

Reading can then proceed from the stream, until the end location is reached, at which time eof processing takes place. file-position can be used to read and set the location, but must not set the location beyond the end.

An aligned pointer as the value of buffer

An aligned pointer is a fixnum which is interpreted as a machine integer, as described in Aligned Pointers and the :aligned type in ftype.htm. The lower 2 (for 32-bit Lisps) or 3 (for 64-bit Lisps) bits of a positive fixnum are zeros which identify the value as a positive fixnum. With the correct specification (as an :aligned value) such fixnums can be passed unconverted to foreign code where they are interpreted as 32 or 64 bit integers whose lower 2 or 3 bits happen to be 0.

Thus if such a fixnum corresponding, as an aligned pointer to values in foreign space, is given as the value of the buffer argument, Lisp will take values from that location from start up to (but not including) end. Note that end must be given a non-negative fixnum value. It is an error if no value is specified for end (since Lisp has then no way of knowing where the data of interest ends).

;; Here is a simple example (using the macro with-input-from-buffer
;; which macroexpands into a call to this function. We get some C space with 
;; aclmalloc-aligned, fill it with 
;; values and access the values. Note that a value is specified for 
;; the END keyword argument.

(defun x ()
  (let ((buf (aclmalloc-aligned 4096)))
    (unwind-protect
        (progn
          ;; Populate buf with sample data
          (dotimes (n 10)
            (setf (sys:memref buf n 0 :unsigned-byte) n))

          (with-input-from-buffer (stream buf 
                                          :start 0 :end 10
                                          :external-format :utf-8)
            (dotimes (n 10)
              (format t "~a => ~a~%" n (read-byte stream)))
            ;; Expect eof
            (read-byte stream)))
      ;; Cleanup forms
      (aclfree-aligned buf))))
0
cl-user(3): :cf foo
;;; Compiling file foo.cl
;;; Writing fasl file foo.fasl
;;; Fasl write complete
cl-user(4): :ld foo
; Fast loading foo.fasl
cl-user(5): (x)
0 => 0
1 => 1
2 => 2
3 => 3
4 => 4
5 => 5
6 => 6
7 => 7
8 => 8
9 => 9
Error: eof encountered on stream
       #<buffer-input-simple-stream  pos 10 @ #x10003aec882>
  [condition type: end-of-file]

See streams.htm for information on the simple-streams implementation in Allegro CL.


Copyright (c) 1998-2019, Franz Inc. Oakland, CA., USA. All rights reserved.
This page was not revised from the 10.0 page.
Created 2019.8.20.

ToCDocOverviewCGDocRelNotesFAQIndexPermutedIndex
Allegro CL version 10.1
Unrevised from 10.0 to 10.1.
10.0 version