1 <!-- -*- DocBook -*- -->
4 <title>Programming Notes</title>
7 <title>Implementation Specific Notes</title>
21 <title>&cmucl;</title>
28 <title>Foreign Object Representation and Access</title>
29 <para> There are two main approaches used to represent foreign
30 objects: an integer that represents an address in memory, and a
31 object that also includes run-time typing. The advantage of
32 run-time typing is the system can dereference pointers and perform
33 array access without those functions requiring a type at the cost
34 of additional overhead to generate and store the run-time
35 typing. The advantage of integer representation, at least for
36 &acl;, is that the compiler can generate inline code to
37 dereference pointers. Further, the overhead of the run-time type
38 information is eliminated. The disadvantage is the program must
40 the type to the functions to dereference objects and array.
45 <title>Optimizing Code Using UFFI</title>
47 <title>Background</title>
49 Two implementions have different techniques to optimize
50 (open-code) foreign objects. &acl; can open-code foreign
52 access if pointers are integers and the type of object is
53 specified in the access function. Thus, &uffi; represents objects
54 in &acl; as integers which don't have type information.
56 &cmucl; works best when keeping objects as typed
57 objects. However, it's compiler can open-code object access when
58 the object type is specified in <function>declare</function>
59 commands and in <varname>:type</varname> specifiers in
60 <function>defstruct</function> and <function>defclass</function>.
61 </para> <para> &lw;, in converse to &acl; and &cmucl; does not do
62 any open coding of object access. &lw;, by default, maintains
63 objects with run-time typing. </para>
66 <title>Cross-Implementation Optimization</title>
68 To fully optimize across platforms, both explicit type
69 information must be passed to dereferencing of pointers and
70 arrays. Though this optimization only helps with &acl;, &uffi;
71 is designed to require this type information be passed the
72 dereference functions. Second, declarations of type should be
73 made in functions, structures, and classes where foreign
74 objects will be help. This will optimize access for &lw;
77 Here is an example that should both methods being used for
78 maximum cross-implementation optimization:
80 (uffi:def-type the-struct-type-def the-struct-type)
81 (let ((a-foreign-struct (allocate-foreign-object 'the-struct-type)))
82 (declare 'the-struct-type-def a-foreign-struct)
83 (get-slot-value a-foreign-struct 'the-struct-type 'field-name))