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
|
<!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>Vocabulary</title>
<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../align.html" title="Chapter 3. Boost.Align">
<link rel="prev" href="reference.html" title="Reference">
<link rel="next" href="compatibility.html" title="Compatibility">
</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="reference.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="compatibility.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.vocabulary"></a><a class="link" href="vocabulary.html" title="Vocabulary">Vocabulary</a>
</h2></div></div></div>
<h4>
<a name="align.vocabulary.h0"></a>
<span class="phrase"><a name="align.vocabulary.basic_align"></a></span><a class="link" href="vocabulary.html#align.vocabulary.basic_align">[basic.align]</a>
</h4>
<p>
Object types have <span class="bold"><strong>alignment requirements</strong></span> which
place restrictions on the addresses at which an object of that type may be
allocated. An <span class="bold"><strong>alignment</strong></span> is an implementation-defined
integer value representing the number of bytes between successive addresses
at which a given object can be allocated. An object type imposes an alignment
requirement on every object of that type; stricter alignment can be requested
using the alignment specifier.
</p>
<p>
A <span class="bold"><strong>fundamental alignment</strong></span> is represented by
an alignment less than or equal to the greatest alignment supported by the
implementation in all contexts, which is equal to <code class="computeroutput"><span class="keyword">alignof</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">max_align_t</span><span class="special">)</span></code>.
The alignment required for a type might be different when it is used as the
type of a complete object and when it is used as the type of a subobject.
</p>
<div class="tip"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../doc/src/images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top">
<pre class="programlisting"><span class="keyword">struct</span> <span class="identifier">B</span> <span class="special">{</span> <span class="keyword">long</span> <span class="keyword">double</span> <span class="identifier">d</span><span class="special">;</span> <span class="special">};</span>
<span class="keyword">struct</span> <span class="identifier">D</span> <span class="special">:</span> <span class="keyword">virtual</span> <span class="identifier">B</span> <span class="special">{</span> <span class="keyword">char</span> <span class="identifier">c</span><span class="special">;</span> <span class="special">};</span>
</pre>
<p>
When <code class="computeroutput"><span class="identifier">D</span></code> is the type of a complete
object, it will have a subobject of type <code class="computeroutput"><span class="identifier">B</span></code>,
so it must be aligned appropriately for a <code class="computeroutput"><span class="keyword">long</span>
<span class="keyword">double</span></code>. If <code class="computeroutput"><span class="identifier">D</span></code>
appears as a subobject of another object that also has <code class="computeroutput"><span class="identifier">B</span></code>
as a virtual base class, the <code class="computeroutput"><span class="identifier">B</span></code>
subobject might be part of a different subobject, reducing the alignment
requirements on the <code class="computeroutput"><span class="identifier">D</span></code> subobject.
</p>
</td></tr>
</table></div>
<p>
The result of the <code class="computeroutput"><span class="keyword">alignof</span></code> operator
reflects the alignment requirement of the type in the complete-object case.
</p>
<p>
An <span class="bold"><strong>extended alignment</strong></span> is represented by an
alignment greater than <code class="computeroutput"><span class="keyword">alignof</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">max_align_t</span><span class="special">)</span></code>.
It is implementation-defined whether any extended alignments are supported
and the contexts in which they are supported. A type having an extended alignment
requirement is an <span class="bold"><strong>over-aligned type</strong></span>.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
Every over-aligned type is or contains a class type to which extended alignment
applies (possibly through a non-static data member).
</p></td></tr>
</table></div>
<p>
Alignments are represented as values of the type <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span></code>.
Valid alignments include only those values returned by an <code class="computeroutput"><span class="keyword">alignof</span></code>
expression for the fundamental types plus an additional implementation-defined
set of values, which may be empty. Every alignment value shall be a non-negative
integral power of two.
</p>
<p>
Alignments have an order from <span class="bold"><strong>weaker</strong></span> to <span class="bold"><strong>stronger</strong></span> or <span class="bold"><strong>stricter</strong></span>
alignments. Stricter alignments have larger alignment values. An address that
satisfies an alignment requirement also satisfies any weaker valid alignment
requirement.
</p>
<p>
The alignment requirement of a complete type can be queried using an <code class="computeroutput"><span class="keyword">alignof</span></code> expression. Furthermore, the types
<code class="computeroutput"><span class="keyword">char</span></code>, <code class="computeroutput"><span class="keyword">signed</span>
<span class="keyword">char</span></code>, and <code class="computeroutput"><span class="keyword">unsigned</span>
<span class="keyword">char</span></code> shall have the weakest alignment
requirement.
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
This enables the character types to be used as the underlying type for an
aligned memory area.
</p></td></tr>
</table></div>
<p>
Comparing alignments is meaningful and provides the obvious results:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem">
Two alignments are equal when their numeric values are equal.
</li>
<li class="listitem">
Two alignments are different when their numeric values are not equal.
</li>
<li class="listitem">
When an alignment is larger than another it represents a stricter alignment.
</li>
</ul></div>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>
The runtime pointer alignment function can be used to obtain an aligned pointer
within a buffer; the aligned-storage templates in the library can be used
to obtain aligned storage.
</p></td></tr>
</table></div>
<p>
If a request for a specific extended alignment in a specific context is not
supported by an implementation, the program is ill-formed. Additionally, a
request for runtime allocation of dynamic storage for which the requested alignment
cannot be honored shall be treated as an allocation failure.
</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 © 2014-2016 Glen Joseph Fernandes<p>
Distributed under the Boost Software License, Version 1.0.
</p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="reference.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="compatibility.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
|