Next Previous Up Top Contents Index

3 FLI Pointers

3.1 Creating and copying pointers

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

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

will return something similar to the following:

#<Pointer to type :INT = #x007608A0>

This is an FLI pointer object, pointing to an object at address#x007608A0 of type:int. Note that the memory address given in the return string is in hexadecimal format, but when using the FLI pointer functions and macros discussed in this chapter you should pass values as decimals.

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

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

However, to make a copy of a pointer it is not sufficient to do the following:

(setq point2 point1)

This simply setspoint2 to contain the same pointer object aspoint1. Thus if the pointer is changed usingpoint1, a similar change is observed when looking inpoint2. To create a distinct copy of the pointer object you should usecopy-pointer, which returns a new pointer object with the same address and type as the old one, as the following example shows.

(setq point3 (fli:copy-pointer point1))

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

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

As a final note, pointers do take up memory. If a pointer is no longer needed it should be deallocated usingfli:free-foreign-object.


LispWorks Foreign Language Interface - 12 Oct 1998

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker