NextPrevUpTopContentsIndex

3.1.1 Creating pointers

Many FLI functions when called return a pointer to the object created. For example, a form such as

(fli:allocate-foreign-object :type :int)

will return something similar to the following:

#<Pointer to type :INT = #x007608A0>

This is a FLI pointer object, pointing to an object at address #x007608A0 of type :int . Note that the memory address is printed in hexadecimal format, but when you use the FLI pointer functions and macros discussed in this chapter, numeric values are interpreted as base 10 unless you use Lisp reader syntax such as #x . .

To use the pointer in the future it needs to be bound to a Lisp variable. This can be done by using setq .

(setq point1 (fli:allocate-foreign-object :type :int)

A pointer can be explicitly created, rather than being returned during the allocation of memory for a FLI object, by using make-pointer. In the next example a pointer is made pointing to an :int type at the address 100 , and is bound to the Lisp variable point2 .

(setq point2 (fli:make-pointer :address 100 :type :int))

For convenience you may wish to define your own pointer types, for example:

(fli:define-foreign-pointer my-pointer-type :int)
 
(setq point3 
      (fli:make-pointer :address 100 
                        :pointer-type 'my-pointer-type))

point3 contains the same type and address information as point2 .


LispWorks Foreign Language Interface User Guide and Reference Manual - 14 Mar 2008

NextPrevUpTopContentsIndex