1 <?xml version='1.0' ?> <!-- -*- DocBook -*- -->
2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
4 <!ENTITY % myents SYSTEM "entities.xml">
9 <title>Programming Notes</title>
11 <sect1 id="impl-specific">
12 <title>Implementation Specific Notes</title>
26 <title>&cmucl;</title>
32 <sect1 id="object-represen">
33 <title>Foreign Object Representation and Access</title>
34 <para> There are two main approaches used to represent foreign
35 objects: an integer that represents an address in memory, and a
36 object that also includes run-time typing. The advantage of
37 run-time typing is the system can dereference pointers and perform
38 array access without those functions requiring a type at the cost
39 of additional overhead to generate and store the run-time
40 typing. The advantage of integer representation, at least for
41 &acl;, is that the compiler can generate inline code to
42 dereference pointers. Further, the overhead of the run-time type
43 information is eliminated. The disadvantage is the program must
45 the type to the functions to dereference objects and array.
49 <sect1 id="optimizing">
50 <title>Optimizing Code Using UFFI</title>
52 <title>Background</title>
54 Two implementions have different techniques to optimize
55 (open-code) foreign objects. &acl; can open-code foreign
57 access if pointers are integers and the type of object is
58 specified in the access function. Thus, &uffi; represents objects
59 in &acl; as integers which don't have type information.
61 &cmucl; works best when keeping objects as typed
62 objects. However, it's compiler can open-code object access when
63 the object type is specified in <function>declare</function>
64 commands and in <varname>:type</varname> specifiers in
65 <function>defstruct</function> and <function>defclass</function>.
66 </para> <para> &lw;, in converse to &acl; and &cmucl; does not do
67 any open coding of object access. &lw;, by default, maintains
68 objects with run-time typing. </para>
71 <title>Cross-Implementation Optimization</title>
73 To fully optimize across platforms, both explicit type
74 information must be passed to dereferencing of pointers and
75 arrays. Though this optimization only helps with &acl;, &uffi;
76 is designed to require this type information be passed the
77 dereference functions. Second, declarations of type should be
78 made in functions, structures, and classes where foreign
79 objects will be help. This will optimize access for &lw;
82 Here is an example that should both methods being used for
83 maximum cross-implementation optimization:
85 (uffi:def-type the-struct-type-def the-struct-type)
86 (let ((a-foreign-struct (allocate-foreign-object 'the-struct-type)))
87 (declare 'the-struct-type-def a-foreign-struct)
88 (get-slot-value a-foreign-struct 'the-struct-type 'field-name))