Update AllegroCL for :long-long on 64-bit platforms
[uffi.git] / doc / notes.xml
1 <?xml version="1.0" encoding="utf-8"?>
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.inc">
5 %myents;
6 ]>
7
8 <chapter id="notes">
9   <title>Programming Notes</title>
10
11   <sect1 id="impl-specific">
12     <title>Implementation Specific Notes</title> 
13     <para>
14     </para>
15       <sect2>
16         <title>&acl;</title>
17         <para>
18         </para>
19       </sect2>
20       <sect2>
21         <title>&lw;</title>
22         <para>
23         </para>
24       </sect2>
25       <sect2>
26         <title>&cmucl;</title>
27         <para>
28         </para>
29       </sect2>
30   </sect1>
31
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
44     then supply
45     the type to the functions to dereference objects and array.
46     </para>
47   </sect1>
48
49   <sect1 id="optimizing">
50     <title>Optimizing Code Using UFFI</title>
51     <sect2>
52       <title>Background</title>
53       <para> 
54         Two implementions have different techniques to optimize
55         (open-code) foreign objects. &acl; can open-code foreign
56         object
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.
60     </para> <para> 
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>
69     </sect2>
70     <sect2>
71       <title>Cross-Implementation Optimization</title>
72       <para>
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;
80       </para>
81       <para>
82         Here is an example that should both methods being used for
83         maximum cross-implementation optimization:
84         <screen>
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))
89         </screen>
90       </para>
91     </sect2>
92   </sect1>
93
94 </chapter>