1<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 2<html> 3<head> 4<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 5<title>Rationale</title> 6<link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css"> 7<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 8<link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset"> 9<link rel="up" href="../align.html" title="Chapter 3. Boost.Align"> 10<link rel="prev" href="../align.html" title="Chapter 3. Boost.Align"> 11<link rel="next" href="examples.html" title="Examples"> 12</head> 13<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 14<table cellpadding="2" width="100%"><tr> 15<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td> 16<td align="center"><a href="../../../index.html">Home</a></td> 17<td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td> 18<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td> 19<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td> 20<td align="center"><a href="../../../more/index.htm">More</a></td> 21</tr></table> 22<hr> 23<div class="spirit-nav"> 24<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="examples.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 25</div> 26<div class="section"> 27<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 28<a name="align.rationale"></a><a class="link" href="rationale.html" title="Rationale">Rationale</a> 29</h2></div></div></div> 30<h4> 31<a name="align.rationale.h0"></a> 32 <span class="phrase"><a name="align.rationale.dynamic_allocation"></a></span><a class="link" href="rationale.html#align.rationale.dynamic_allocation">Dynamic 33 allocation</a> 34 </h4> 35<p> 36 C++11 added the ability to specify increased alignment (over-alignment) for 37 class types. Unfortunately, <code class="computeroutput"><span class="special">::</span><span class="keyword">operator</span> <span class="keyword">new</span></code> 38 allocation functions, <code class="computeroutput"><span class="keyword">new</span></code> expressions 39 and the Default Allocator, <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator</span></code>, 40 do not support dynamic memory allocation of over-aligned data. This library 41 provides allocation functions and allocators that respect the alignment requirements 42 of a type and so are suitable for allocating memory for over-aligned types. 43 </p> 44<div class="variablelist"> 45<p class="title"><b></b></p> 46<dl class="variablelist"> 47<dt><span class="term"><code class="computeroutput"><span class="identifier">aligned_alloc</span><span class="special">(</span><span class="identifier">alignment</span><span class="special">,</span> <span class="identifier">size</span><span class="special">)</span></code></span></dt> 48<dd><p> 49 Replaces <code class="computeroutput"><span class="special">::</span><span class="keyword">operator</span> 50 <span class="keyword">new</span><span class="special">(</span><span class="identifier">size</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">nothrow</span><span class="special">)</span></code> 51 </p></dd> 52<dt><span class="term"><code class="computeroutput"><span class="identifier">aligned_free</span><span class="special">(</span><span class="identifier">pointer</span><span class="special">)</span></code></span></dt> 53<dd><p> 54 Replaces <code class="computeroutput"><span class="special">::</span><span class="keyword">operator</span> 55 <span class="keyword">delete</span><span class="special">(</span><span class="identifier">pointer</span><span class="special">,</span> 56 <span class="identifier">std</span><span class="special">::</span><span class="identifier">nothrow</span><span class="special">)</span></code> 57 </p></dd> 58<dt><span class="term"><code class="computeroutput"><span class="identifier">aligned_allocator</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code></span></dt> 59<dd><p> 60 Replaces <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">allocator</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> 61 </p></dd> 62<dt><span class="term"><code class="computeroutput"><span class="identifier">aligned_allocator_adaptor</span><span class="special"><</span><span class="identifier">Allocator</span><span class="special">></span></code></span></dt> 63<dd><p> 64 Replaces use of Allocator 65 </p></dd> 66<dt><span class="term"><code class="computeroutput"><span class="identifier">aligned_delete</span></code></span></dt> 67<dd><p> 68 Replaces <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">default_delete</span><span class="special"><</span><span class="identifier">T</span><span class="special">></span></code> 69 </p></dd> 70</dl> 71</div> 72<h4> 73<a name="align.rationale.h1"></a> 74 <span class="phrase"><a name="align.rationale.pointer_alignment"></a></span><a class="link" href="rationale.html#align.rationale.pointer_alignment">Pointer 75 alignment</a> 76 </h4> 77<p> 78 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 79 pointer value. Unfortunately some C++ standard library implementations do not 80 support it yet (libstdc++ as far as gcc 4.8.0) and other standard library implementations 81 implement it incorrectly (dinkumware in msvc11.0). This library provides it 82 for those implementations and also for C++03 compilers where it is equally 83 useful. 84 </p> 85<h4> 86<a name="align.rationale.h2"></a> 87 <span class="phrase"><a name="align.rationale.querying_alignment"></a></span><a class="link" href="rationale.html#align.rationale.querying_alignment">Querying 88 alignment</a> 89 </h4> 90<p> 91 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 92 to query the alignment requirement of a type. Unfortunately some C++ standard 93 library vendors do not implement it in an entirely standard conforming manner, 94 such as for array types (libc++ as far as clang 3.4). Other vendor implementations 95 report incorrect values for certain types, such as pointer to members (msvc 96 14.0). This library provides it for those implementations and also for C++03 97 compilers where it is equally useful. 98 </p> 99<h4> 100<a name="align.rationale.h3"></a> 101 <span class="phrase"><a name="align.rationale.hinting_alignment"></a></span><a class="link" href="rationale.html#align.rationale.hinting_alignment">Hinting 102 alignment</a> 103 </h4> 104<p> 105 Allocating aligned memory is sometimes not enough to ensure that optimal code 106 is generated. Developers use specific compiler intrinsics to notify the compiler 107 of a given alignment property of a memory block. This library provides a macro, 108 <code class="computeroutput"><span class="identifier">BOOST_ALIGN_ASSUME_ALIGNED</span></code>, 109 to abstract that functionality for compilers with the appropriate intrinsics. 110 </p> 111<h4> 112<a name="align.rationale.h4"></a> 113 <span class="phrase"><a name="align.rationale.checking_alignment"></a></span><a class="link" href="rationale.html#align.rationale.checking_alignment">Checking 114 alignment</a> 115 </h4> 116<p> 117 This library provides a function, <code class="computeroutput"><span class="identifier">is_aligned</span></code> 118 to test the alignment of a pointer value. It is generally useful in assertions 119 to validate that memory is correctly aligned. 120 </p> 121</div> 122<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 123<td align="left"></td> 124<td align="right"><div class="copyright-footer">Copyright © 2014-2017 Glen 125 Joseph Fernandes<p> 126 Distributed under the Boost Software License, Version 1.0. 127 </p> 128</div></td> 129</tr></table> 130<hr> 131<div class="spirit-nav"> 132<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="examples.html"><img src="../../../doc/src/images/next.png" alt="Next"></a> 133</div> 134</body> 135</html> 136