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.75.2">
7 <link rel="home" href="../../index.html" title="Chapter 1. Context">
8 <link rel="up" href="../abstract_context.html" title="Context classes">
9 <link rel="prev" href="ccontext.html" title="Class captured_context">
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="ccontext.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../abstract_context.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><h3 class="title">
27 <a name="context.abstract_context.stack"></a><a class="link" href="stack.html" title="Stack allocation">Stack allocation</a>
28 </h3></div></div></div>
30 <dt><span class="section"><a href="stack/protected_fixedsize.html">Class
31 <span class="emphasis"><em>protected_fixedsize</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 <span class="emphasis"><em>segmented_stack</em></span></a></span></dt>
34 <dt><span class="section"><a href="stack/stack_traits.html">Class
35 <span class="emphasis"><em>stack_traits</em></span></a></span></dt>
36 <dt><span class="section"><a href="stack/stack_context.html">Class
37 <span class="emphasis"><em>stack_context</em></span></a></span></dt>
38 <dt><span class="section"><a href="stack/valgrind.html">Support for
39 valgrind</a></span></dt>
42 The memory used by the stack is allocated/deallocated via a <span class="emphasis"><em>StackAllocator</em></span>
43 which is required to model a <span class="emphasis"><em>stack-allocator concept</em></span>.
46 <a name="context.abstract_context.stack.h0"></a>
47 <span><a name="context.abstract_context.stack._emphasis_stack_allocator_concept__emphasis_"></a></span><a class="link" href="stack.html#context.abstract_context.stack._emphasis_stack_allocator_concept__emphasis_"><span class="emphasis"><em>stack-allocator
48 concept</em></span></a>
51 A <span class="emphasis"><em>StackAllocator</em></span> must satisfy the <span class="emphasis"><em>stack-allocator
52 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>
53 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>
54 is a <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span></code>:
56 <div class="informaltable"><table class="table">
83 <code class="computeroutput"><span class="identifier">a</span><span class="special">(</span><span class="identifier">size</span><span class="special">)</span></code>
90 creates a stack allocator
97 <code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><span class="identifier">allocate</span><span class="special">()</span></code>
102 <code class="computeroutput"><span class="identifier">stack_context</span></code>
114 <code class="computeroutput"><span class="identifier">a</span><span class="special">.</span><span class="identifier">deallocate</span><span class="special">(</span>
115 <span class="identifier">sctx</span><span class="special">)</span></code>
120 <code class="computeroutput"><span class="keyword">void</span></code>
125 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>
131 <div class="important"><table border="0" summary="Important">
133 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../../doc/src/images/important.png"></td>
134 <th align="left">Important</th>
136 <tr><td align="left" valign="top"><p>
137 The implementation of <code class="computeroutput"><span class="identifier">allocate</span><span class="special">()</span></code> might include logic to protect against
138 exceeding the context's available stack size rather than leaving it as
142 <div class="important"><table border="0" summary="Important">
144 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Important]" src="../../../../../../doc/src/images/important.png"></td>
145 <th align="left">Important</th>
147 <tr><td align="left" valign="top"><p>
148 Calling <code class="computeroutput"><span class="identifier">deallocate</span><span class="special">()</span></code>
149 with a <code class="computeroutput"><span class="identifier">stack_context</span></code> not
150 set by <code class="computeroutput"><span class="identifier">allocate</span><span class="special">()</span></code>
151 results in undefined behaviour.
154 <div class="note"><table border="0" summary="Note">
156 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td>
157 <th align="left">Note</th>
159 <tr><td align="left" valign="top"><p>
160 The stack is not required to be aligned; alignment takes place inside
161 <span class="emphasis"><em>execution_context</em></span>.
164 <div class="note"><table border="0" summary="Note">
166 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td>
167 <th align="left">Note</th>
169 <tr><td align="left" valign="top"><p>
170 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
171 stack (growing downwards) or the bottom of the stack (growing upwards).
175 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
176 <td align="left"></td>
177 <td align="right"><div class="copyright-footer">Copyright © 2014 Oliver Kowalke<p>
178 Distributed under the Boost Software License, Version 1.0. (See accompanying
179 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>)
184 <div class="spirit-nav">
185 <a accesskey="p" href="ccontext.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../abstract_context.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>