summaryrefslogtreecommitdiff
path: root/doc/html/align/rationale.html
blob: 42029feab7cf0ce8f6beb30f7c813ce6309d832d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>Rationale</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../align.html" title="Chapter&#160;2.&#160;Boost.Align">
<link rel="prev" href="../align.html" title="Chapter&#160;2.&#160;Boost.Align">
<link rel="next" href="tutorial.html" title="Tutorial">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
<td align="center"><a href="../../../index.html">Home</a></td>
<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../align.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../align.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="align.rationale"></a><a class="link" href="rationale.html" title="Rationale">Rationale</a>
</h2></div></div></div>
<h4>
<a name="align.rationale.h0"></a>
      <span class="phrase"><a name="align.rationale.dynamic_allocation"></a></span><a class="link" href="rationale.html#align.rationale.dynamic_allocation">Dynamic
      allocation</a>
    </h4>
<p>
      C++11 added the ability to specify increased alignment (over-alignment) for
      class types. Unfortunately, <code class="computeroutput"><span class="special">::</span><span class="keyword">operator</span> <span class="keyword">new</span></code>
      allocation functions, <code class="computeroutput"><span class="keyword">new</span></code> expressions,
      and the default allocator, <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator</span></code>,
      do not support dynamic memory allocation of over-aligned data. This library
      provides allocation functions, allocators, allocator adaptors, and deleters,
      that are alignment aware.
    </p>
<div class="table">
<a name="align.rationale.boost_align_solutions"></a><p class="title"><b>Table&#160;2.2.&#160;Boost.Align solutions</b></p>
<div class="table-contents"><table class="table" summary="Boost.Align solutions">
<colgroup>
<col>
<col>
</colgroup>
<thead><tr>
<th>
              <p>
                Problem
              </p>
            </th>
<th>
              <p>
                Solution
              </p>
            </th>
</tr></thead>
<tbody>
<tr>
<td>
              <p>
                <code class="computeroutput"><span class="special">::</span><span class="keyword">operator</span>
                <span class="keyword">new</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">,</span>
                <span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">no_throw_t</span><span class="special">&amp;)</span></code>
              </p>
            </td>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">aligned_alloc</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">,</span>
                <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">)</span></code>
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                <code class="computeroutput"><span class="special">::</span><span class="keyword">operator</span>
                <span class="keyword">delete</span><span class="special">(</span><span class="keyword">void</span><span class="special">*)</span></code>
              </p>
            </td>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">aligned_free</span><span class="special">(</span><span class="keyword">void</span><span class="special">*)</span></code>
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>
              </p>
            </td>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">aligned_allocator</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">Allocator</span></code>
              </p>
            </td>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">aligned_allocator_adaptor</span><span class="special">&lt;</span><span class="identifier">Allocator</span><span class="special">&gt;</span></code>
              </p>
            </td>
</tr>
<tr>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">default_delete</span><span class="special">&lt;</span><span class="identifier">T</span><span class="special">&gt;</span></code>
              </p>
            </td>
<td>
              <p>
                <code class="computeroutput"><span class="identifier">aligned_delete</span></code>
              </p>
            </td>
</tr>
</tbody>
</table></div>
</div>
<br class="table-break"><h4>
<a name="align.rationale.h1"></a>
      <span class="phrase"><a name="align.rationale.alignment_functions"></a></span><a class="link" href="rationale.html#align.rationale.alignment_functions">Alignment
      functions</a>
    </h4>
<p>
      C++11 provided <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">align</span></code> in the standard library to align a
      pointer value. Unfortunately some C++ standard library implementations do not
      support it yet (libstdc++ as far as gcc 4.8.0) and other standard library implementations
      implement it incorrectly (dinkumware in msvc 11.0). This library provides it
      for those implementations and also for C++03 compilers where it is equally
      useful.
    </p>
<h4>
<a name="align.rationale.h2"></a>
      <span class="phrase"><a name="align.rationale.alignment_traits"></a></span><a class="link" href="rationale.html#align.rationale.alignment_traits">Alignment
      traits</a>
    </h4>
<p>
      C++11 provided the <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">alignment_of</span></code> trait in the standard library
      to query the alignment requirement of a type. Unfortunately some C++ standard
      library vendors do not implement it in an entirely standard conforming manner,
      such as for array types (libc++ as far as clang 3.4). Other vendor implementations
      report incorrect values for certain types, such as pointer to members (msvc
      14.0). This library provides it for those implementations and also for C++03
      compilers where it is equally useful.
    </p>
<h4>
<a name="align.rationale.h3"></a>
      <span class="phrase"><a name="align.rationale.alignment_hints"></a></span><a class="link" href="rationale.html#align.rationale.alignment_hints">Alignment
      hints</a>
    </h4>
<p>
      Allocating aligned memory is sometimes not enough to ensure that optimal code
      is generated. Developers use specific compiler intrinsics to notify the compiler
      of a given alignment property of a memory block. This library provides a macro
      to abstract that functionality for compilers with the appropriate intrinsics.
    </p>
<h4>
<a name="align.rationale.h4"></a>
      <span class="phrase"><a name="align.rationale.alignment_testing"></a></span><a class="link" href="rationale.html#align.rationale.alignment_testing">Alignment
      testing</a>
    </h4>
<p>
      This library provides a function to test the alignment of a pointer value.
      It is generally useful in assertions to validate that memory is correctly aligned.
    </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright &#169; 2014 Glen Joseph Fernandes<p>
        Distributed under the <a href="http://boost.org/LICENSE_1_0.txt" target="_top">Boost
        Software License, Version 1.0</a>.
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../align.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../align.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="tutorial.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>