1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Class standard_stack_allocator</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. Coroutine"> 8<link rel="up" href="../stack.html" title="Stack allocation"> 9<link rel="prev" href="protected_stack_allocator.html" title="Class protected_stack_allocator"> 10<link rel="next" href="segmented_stack_allocator.html" title="Class segmented_stack_allocator"> 11</head> 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> 20</tr></table> 21<hr> 22<div class="spirit-nav"> 23<a accesskey="p" href="protected_stack_allocator.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../stack.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="segmented_stack_allocator.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 24</div> 25<div class="section"> 26<div class="titlepage"><div><div><h3 class="title"> 27<a name="coroutine.stack.standard_stack_allocator"></a><a class="link" href="standard_stack_allocator.html" title="Class standard_stack_allocator">Class <span class="emphasis"><em>standard_stack_allocator</em></span></a> 28</h3></div></div></div> 29<p> 30 <span class="bold"><strong>Boost.Coroutine</strong></span> provides the class <span class="emphasis"><em>standard_stack_allocator</em></span> 31 which models the <span class="emphasis"><em>stack-allocator concept</em></span>. In contrast 32 to <span class="emphasis"><em>protected_stack_allocator</em></span> it does not append a guard 33 page at the end of each stack. The memory is simply managed by <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">malloc</span><span class="special">()</span></code> and <code class="computeroutput"><span class="identifier">std</span><span class="special">::</span><span class="identifier">free</span><span class="special">()</span></code>. 34 </p> 35<div class="note"><table border="0" summary="Note"> 36<tr> 37<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../doc/src/images/note.png"></td> 38<th align="left">Note</th> 39</tr> 40<tr><td align="left" valign="top"><p> 41 The <span class="emphasis"><em>standard_stack_allocator</em></span> is the default stack 42 allocator. 43 </p></td></tr> 44</table></div> 45<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special"><</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">coroutine</span><span class="special">/</span><span class="identifier">standard_stack_allocator</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">></span> 46 47<span class="keyword">template</span><span class="special"><</span> <span class="keyword">typename</span> <span class="identifier">traitsT</span> <span class="special">></span> 48<span class="keyword">struct</span> <span class="identifier">standard_stack_allocator</span> 49<span class="special">{</span> 50 <span class="keyword">typedef</span> <span class="identifier">traitT</span> <span class="identifier">traits_type</span><span class="special">;</span> 51 52 <span class="keyword">void</span> <span class="identifier">allocate</span><span class="special">(</span> <span class="identifier">stack_context</span> <span class="special">&,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">size</span><span class="special">);</span> 53 54 <span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span> <span class="identifier">stack_context</span> <span class="special">&);</span> 55<span class="special">}</span> 56 57<span class="keyword">typedef</span> <span class="identifier">basic_standard_stack_allocator</span><span class="special"><</span> <span class="identifier">stack_traits</span> <span class="special">></span> <span class="identifier">standard_stack_allocator</span> 58</pre> 59<h5> 60<a name="coroutine.stack.standard_stack_allocator.h0"></a> 61 <span class="phrase"><a name="coroutine.stack.standard_stack_allocator._code__phrase_role__keyword__void__phrase___phrase_role__identifier__allocate__phrase__phrase_role__special_____phrase___phrase_role__identifier__stack_context__phrase___phrase_role__special___amp___phrase___phrase_role__identifier__sctx__phrase__phrase_role__special_____phrase___phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__size__phrase__phrase_role__special_____phrase___code_"></a></span><a class="link" href="standard_stack_allocator.html#coroutine.stack.standard_stack_allocator._code__phrase_role__keyword__void__phrase___phrase_role__identifier__allocate__phrase__phrase_role__special_____phrase___phrase_role__identifier__stack_context__phrase___phrase_role__special___amp___phrase___phrase_role__identifier__sctx__phrase__phrase_role__special_____phrase___phrase_role__identifier__std__phrase__phrase_role__special______phrase__phrase_role__identifier__size_t__phrase___phrase_role__identifier__size__phrase__phrase_role__special_____phrase___code_"><code class="computeroutput"><span class="keyword">void</span> <span class="identifier">allocate</span><span class="special">(</span> <span class="identifier">stack_context</span> 62 <span class="special">&</span> <span class="identifier">sctx</span><span class="special">,</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> <span class="identifier">size</span><span class="special">)</span></code></a> 63 </h5> 64<div class="variablelist"> 65<p class="title"><b></b></p> 66<dl class="variablelist"> 67<dt><span class="term">Preconditions:</span></dt> 68<dd><p> 69 <code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">minimum_size</span><span class="special">()</span> 70 <span class="special"><=</span> <span class="identifier">size</span></code> 71 and <code class="computeroutput"><span class="special">!</span> <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">is_unbounded</span><span class="special">()</span> <span class="special">&&</span> 72 <span class="special">(</span> <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">maximum_size</span><span class="special">()</span> <span class="special">>=</span> <span class="identifier">size</span><span class="special">)</span></code>. 73 </p></dd> 74<dt><span class="term">Effects:</span></dt> 75<dd><p> 76 Allocates memory of at least <code class="computeroutput"><span class="identifier">size</span></code> 77 bytes and stores a pointer to the stack and its actual size in <code class="computeroutput"><span class="identifier">sctx</span></code>. Depending on the architecture 78 (the stack grows downwards/upwards) the stored address is the highest/lowest 79 address of the stack. 80 </p></dd> 81</dl> 82</div> 83<h5> 84<a name="coroutine.stack.standard_stack_allocator.h1"></a> 85 <span class="phrase"><a name="coroutine.stack.standard_stack_allocator._code__phrase_role__keyword__void__phrase___phrase_role__identifier__deallocate__phrase__phrase_role__special_____phrase___phrase_role__identifier__stack_context__phrase___phrase_role__special___amp___phrase___phrase_role__identifier__sctx__phrase__phrase_role__special_____phrase___code_"></a></span><a class="link" href="standard_stack_allocator.html#coroutine.stack.standard_stack_allocator._code__phrase_role__keyword__void__phrase___phrase_role__identifier__deallocate__phrase__phrase_role__special_____phrase___phrase_role__identifier__stack_context__phrase___phrase_role__special___amp___phrase___phrase_role__identifier__sctx__phrase__phrase_role__special_____phrase___code_"><code class="computeroutput"><span class="keyword">void</span> <span class="identifier">deallocate</span><span class="special">(</span> <span class="identifier">stack_context</span> 86 <span class="special">&</span> <span class="identifier">sctx</span><span class="special">)</span></code></a> 87 </h5> 88<div class="variablelist"> 89<p class="title"><b></b></p> 90<dl class="variablelist"> 91<dt><span class="term">Preconditions:</span></dt> 92<dd><p> 93 <code class="computeroutput"><span class="identifier">sctx</span><span class="special">.</span><span class="identifier">sp</span></code> is valid, <code class="computeroutput"><span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">minimum_size</span><span class="special">()</span> <span class="special"><=</span> <span class="identifier">sctx</span><span class="special">.</span><span class="identifier">size</span></code> and <code class="computeroutput"><span class="special">!</span> 94 <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">is_unbounded</span><span class="special">()</span> 95 <span class="special">&&</span> <span class="special">(</span> 96 <span class="identifier">traits_type</span><span class="special">::</span><span class="identifier">maximum_size</span><span class="special">()</span> 97 <span class="special">>=</span> <span class="identifier">sctx</span><span class="special">.</span><span class="identifier">size</span><span class="special">)</span></code>. 98 </p></dd> 99<dt><span class="term">Effects:</span></dt> 100<dd><p> 101 Deallocates the stack space. 102 </p></dd> 103</dl> 104</div> 105</div> 106<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 107<td align="left"></td> 108<td align="right"><div class="copyright-footer">Copyright © 2009 Oliver Kowalke<p> 109 Distributed under the Boost Software License, Version 1.0. (See accompanying 110 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>) 111 </p> 112</div></td> 113</tr></table> 114<hr> 115<div class="spirit-nav"> 116<a accesskey="p" href="protected_stack_allocator.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../stack.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="segmented_stack_allocator.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a> 117</div> 118</body> 119</html> 120