File: shareable-vectors.txt

package info (click to toggle)
acl2 8.6%2Bdfsg-2
  • links: PTS
  • area: main
  • in suites: trixie
  • size: 1,111,420 kB
  • sloc: lisp: 17,818,294; java: 125,359; python: 28,122; javascript: 23,458; cpp: 18,851; ansic: 11,569; perl: 7,678; xml: 5,591; sh: 3,976; makefile: 3,833; ruby: 2,633; yacc: 1,126; ml: 763; awk: 295; csh: 233; lex: 197; php: 178; tcl: 49; asm: 23; haskell: 17
file content (44 lines) | stat: -rw-r--r-- 1,537 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

# Shareable Byte Vectors

Function: make-shareable-byte-vector size

Create a vector of element type (UNSIGNED-BYTE 8) suitable for passing
to WITH-POINTER-TO-VECTOR-DATA.

;; Minimal implementation:
(defun make-shareable-byte-vector (size)
  (make-array size :element-type '(unsigned-byte 8)))


Macro: with-pointer-to-vector-data (ptr-var vector) &body body

Bind PTR-VAR to a pointer to the data contained in a shareable byte
vector.

VECTOR must be a shareable vector created by MAKE-SHAREABLE-BYTE-VECTOR.

PTR-VAR may point directly into the Lisp vector data, or it may point
to a temporary block of foreign memory which will be copied to and
from VECTOR.

Both the pointer object in PTR-VAR and the memory it points to have
dynamic extent.  The results are undefined if foreign code attempts to
access this memory outside this dynamic contour.

The implementation must guarantee the memory pointed to by PTR-VAR
will not be moved during the dynamic contour of this operator, either
by creating the vector in a static area or temporarily disabling the
garbage collector.

;; Minimal (copying) implementation:
(defmacro with-pointer-to-vector-data ((ptr-var vector) &body body)
  (let ((vector-var (gensym))
        (size-var (gensym)))
    `(let* ((,vector-var ,vector)
            (,size-var (length ,vector-var)))
       (with-foreign-ptr (,ptr-var ,size-var)
         (mem-write-vector ,vector-var ,ptr :uint8)
         (prog1
             (progn ,@body)
           (mem-read-vector ,vector-var ,ptr-var :uint8 ,size-var))))))