Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/function/doc/misc.xml @ 35

Last change on this file since 35 was 29, checked in by landauf, 16 years ago

updated boost from 1_33_1 to 1_34_1

File size: 4.7 KB
Line 
1<?xml version="1.0" encoding="utf-8"?>
2<!--
3   Copyright (c) 2002 Douglas Gregor <doug.gregor -at- gmail.com>
4 
5   Distributed under the Boost Software License, Version 1.0.
6   (See accompanying file LICENSE_1_0.txt or copy at
7   http://www.boost.org/LICENSE_1_0.txt)
8  -->
9<!DOCTYPE library PUBLIC "-//Boost//DTD BoostBook XML V1.0//EN"
10  "http://www.boost.org/tools/boostbook/dtd/boostbook.dtd">
11<section id="function.misc" last-revision="$Date: 2006/11/03 19:41:09 $">
12  <title>Miscellaneous Notes</title>
13
14  <section>
15    <title>Boost.Function vs. Function Pointers</title>
16<para>Boost.Function has several advantages over function pointers, namely:
17
18<itemizedlist spacing="compact">
19   <listitem><para>Boost.Function allows arbitrary compatible function objects to be targets (instead of requiring an exact function signature).</para></listitem>
20   <listitem><para>Boost.Function may be used with argument-binding and other function object construction libraries.</para></listitem>
21   <listitem><para>Boost.Function has predictible behavior when an empty function object is called. </para></listitem>
22</itemizedlist></para>
23
24<para> And, of course, function pointers have several advantages over Boost.Function:
25
26<itemizedlist spacing="compact">
27    <listitem><para> Function pointers are smaller (the size of one pointer instead of three) </para></listitem>
28    <listitem><para> Function pointers are faster (Boost.Function may require two calls through function pointers) </para></listitem>
29    <listitem><para> Function pointers are backward-compatible with C libraries.</para></listitem>
30    <listitem><para> More readable error messages. </para></listitem>
31</itemizedlist>
32</para>
33  </section>
34
35  <section>
36    <title>Performance</title>
37
38<section>
39  <title>Function object wrapper size</title>
40<para> Function object wrappers will be the size of two function pointers plus one function pointer or data pointer (whichever is larger). On common 32-bit platforms, this amounts to 12 bytes per wrapper. Additionally, the function object target will be allocated on the heap.</para>
41</section>
42
43<section>
44  <title>Copying efficiency</title>
45<para> Copying function object wrappers may require allocating memory for a copy of the function object target. The default allocator may be replaced with a faster custom allocator or one may choose to allow the function object wrappers to only store function object targets by reference (using <computeroutput>ref</computeroutput>) if the cost of this cloning becomes prohibitive.</para>
46 </section>
47
48<section>
49  <title>Invocation efficiency</title>
50<para> With a properly inlining compiler, an invocation of a function object requires one call through a function pointer. If the call is to a free function pointer, an additional call must be made to that function pointer (unless the compiler has very powerful interprocedural analysis).</para>
51  </section>
52</section>
53
54  <section>
55    <title>Combatting virtual function "bloat"</title>
56<para> The use of virtual functions tends to cause 'code bloat' on many compilers. When a class contains a virtual function, it is necessary to emit an additional function that classifies the type of the object. It has been our experience that these auxiliary functions increase the size of the executable significantly when many <computeroutput>boost::function</computeroutput> objects are used. </para>
57
58<para> In Boost.Function, an alternative but equivalent approach was taken using free functions instead of virtual functions. The Boost.Function object essentially holds two pointers to make a valid target call: a void pointer to the function object it contains and a void pointer to an "invoker" that can call the function object, given the function pointer. This invoker function performs the argument and return value conversions Boost.Function provides. A third pointer points to a free function called the "manager", which handles the cloning and destruction of function objects. The scheme is typesafe because the only functions that actually handle the function object, the invoker and the manager, are instantiated given the type of the function object, so they can safely cast the incoming void pointer (the function object pointer) to the appropriate type.</para>
59  </section>
60
61  <section>
62    <title>Acknowledgements</title> 
63
64    <para> Many people were involved in the construction of this
65    library. William Kempf, Jesse Jones and Karl Nelson were all
66    extremely helpful in isolating an interface and scope for the
67    library. John Maddock managed the formal review, and many
68    reviewers gave excellent comments on interface, implementation,
69    and documentation. Peter Dimov led us to the function
70    declarator-based syntax.</para>
71  </section>
72</section>
Note: See TracBrowser for help on using the repository browser.