3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Stack allocation</title>
5 <link rel="stylesheet" href="../../../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
7 <link rel="home" href="../index.html" title="Chapter 1. Context">
8 <link rel="up" href="../index.html" title="Chapter 1. Context">
9 <link rel="prev" href="cc/class__continuation_.html" title="Class continuation">
10 <link rel="next" href="stack/protected_fixedsize.html" title="Class protected_fixedsize">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../boost.png"></td>
15 <td align="center"><a href="../../../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="cc/class__continuation_.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="stack/protected_fixedsize.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>
26 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
27 <a name="context.stack"></a><a name="stack"></a><a class="link" href="stack.html" title="Stack allocation">Stack allocation</a>
28 </h2></div></div></div>
29 <div class="toc"><dl class="toc">
30 <dt><span class="section"><a href="stack/protected_fixedsize.html">Class <span class="emphasis"><em>protected_fixedsize</em></span></a></span></dt>
31 <dt><span class="section"><a href="stack/pooled_fixedsize.html">Class <span class="emphasis"><em>pooled_fixedsize_stack</em></span></a></span></dt>
32 <dt><span class="section"><a href="stack/fixedsize.html">Class <span class="emphasis"><em>fixedsize_stack</em></span></a></span></dt>
33 <dt><span class="section"><a href="stack/segmented.html">Class
34 <span class="emphasis"><em>segmented_stack</em></span></a></span></dt>
35 <dt><span class="section"><a href="stack/stack_traits.html">Class <span class="emphasis"><em>stack_traits</em></span></a></span></dt>
36 <dt><span class="section"><a href="stack/stack_context.html">Class <span class="emphasis"><em>stack_context</em></span></a></span></dt>
37 <dt><span class="section"><a href="stack/valgrind.html">Support for valgrind</a></span></dt>
38 <dt><span class="section"><a href="stack/sanitizers.html">Support for sanitizers</a></span></dt>
41 The memory used by the stack is allocated/deallocated via a <span class="emphasis"><em>StackAllocator</em></span>
42 which is required to model a <span class="emphasis"><em>stack-allocator concept</em></span>.
45 <a name="context.stack.h0"></a>
46 <span class="phrase"><a name="context.stack._emphasis_stack_allocator_concept__emphasis_"></a></span><a class="link" href="stack.html#context.stack._emphasis_stack_allocator_concept__emphasis_"><span class="emphasis"><em>stack-allocator
47 concept</em></span></a>
50 A <span class="emphasis"><em>StackAllocator</em></span> must satisfy the <span class="emphasis"><em>stack-allocator
51 concept</em></span> requirements shown in the following table, in which <code class="computeroutput"><span class="identifier">a</span></code> is an object of a <span class="emphasis"><em>StackAllocator</em></span>
52 type, <code class="computeroutput"><span class="identifier">sctx</span></code> is a <code class="computeroutput"><span class="identifier">stack_context</span></code>, and <code class="computeroutput"><span class="identifier">size</span></code>
53 is a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span></code>:
55 <div class="informaltable"><table class="table">
82 <code class="computeroutput"><span class="identifier">a</span><span class="special">(</span><span class="identifier">size</span><span class="special">)</span></code>
89 creates a stack allocator
96 <code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><span class="identifier">allocate</span><span class="special">()</span></code>
101 <code class="computeroutput"><span class="identifier">stack_context</span></code>
113 <code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><span class="identifier">deallocate</span><span class="special">(</span>
114 <span class="identifier">sctx</span><span class="special">)</span></code>
119 <code class="computeroutput"><span class="keyword">void</span></code>
124 deallocates the stack created by <code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><span class="identifier">allocate</span><span class="special">()</span></code>
130 <div class="important"><table border="0" summary="Important">
132 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../doc/src/images/important.png"></td>
133 <th align="left">Important</th>
135 <tr><td align="left" valign="top"><p>
136 The implementation of <code class="computeroutput"><span class="identifier">allocate</span><span class="special">()</span></code> might include logic to protect against
137 exceeding the context's available stack size rather than leaving it as undefined
141 <div class="important"><table border="0" summary="Important">
143 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../doc/src/images/important.png"></td>
144 <th align="left">Important</th>
146 <tr><td align="left" valign="top"><p>
147 Calling <code class="computeroutput"><span class="identifier">deallocate</span><span class="special">()</span></code>
148 with a <code class="computeroutput"><span class="identifier">stack_context</span></code> not
149 set by <code class="computeroutput"><span class="identifier">allocate</span><span class="special">()</span></code>
150 results in undefined behaviour.
153 <div class="note"><table border="0" summary="Note">
155 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../doc/src/images/note.png"></td>
156 <th align="left">Note</th>
158 <tr><td align="left" valign="top"><p>
159 Depending on the architecture <code class="computeroutput"><span class="identifier">allocate</span><span class="special">()</span></code> stores an address from the top of the stack
160 (growing downwards) or the bottom of the stack (growing upwards).
164 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
165 <td align="left"></td>
166 <td align="right"><div class="copyright-footer">Copyright © 2014 Oliver Kowalke<p>
167 Distributed under the Boost Software License, Version 1.0. (See accompanying
168 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
173 <div class="spirit-nav">
174 <a accesskey="p" href="cc/class__continuation_.html"><img src="../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="stack/protected_fixedsize.html"><img src="../../../../../doc/src/images/next.png" alt="Next"></a>