代码拉取完成,页面将自动刷新
<!-- HTML header for doxygen 1.8.16-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.18"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>memory: memory_stack< BlockOrRawAllocator > Class Template Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">memory
</div>
</td>
</tr>
</tbody>
</table>
</div>
<div id="main-nav">
<ul class="sm sm-dox" id="main-menu">
<li><a href="index.html">Main Page</a></li>
<li><a href="md_doc_tutorial.html">Tutorial</a></li>
<li><a href="namespacefoonathan_1_1memory.html">Index</a></li>
<li><a href="files.html">Files</a></li>
</ul>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.18 -->
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="namespacefoonathan.html">foonathan</a></li><li class="navelem"><a class="el" href="namespacefoonathan_1_1memory.html">memory</a></li><li class="navelem"><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html">memory_stack</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="summary">
<a href="#pub-types">Typedefs</a> |
<a href="#pub-methods">Member Functions</a> </div>
<div class="headertitle">
<div class="title">memory_stack< BlockOrRawAllocator > Class Template Reference<div class="ingroups"><a class="el" href="group__allocator.html">Allocator implementations</a></div></div> </div>
</div><!--header-->
<div class="contents">
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><h3>template<class BlockOrRawAllocator = default_allocator><br />
class foonathan::memory::memory_stack< BlockOrRawAllocator ></h3>
<p>A stateful <a href="md_doc_concepts.html#concept_rawallocator">RawAllocator</a> that provides stack-like (LIFO) allocations. </p>
<p>It uses a <a class="el" href="classfoonathan_1_1memory_1_1memory__arena.html">memory_arena</a> with a given <code>BlockOrRawAllocator</code> defaulting to <a class="el" href="classfoonathan_1_1memory_1_1growing__block__allocator.html">growing_block_allocator</a> to allocate huge blocks and saves a marker to the current top. Allocation simply moves this marker by the appropriate number of bytes and returns the pointer at the old marker position, deallocation is not directly supported, only setting the marker to a previously queried position. </p>
</div><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-types"></a>
Typedefs</h2></td></tr>
<tr class="memitem:a7fd26a8539389ffa2a4b1d1a7b6b839c"><td class="memItemLeft" align="right" valign="top"><a id="a7fd26a8539389ffa2a4b1d1a7b6b839c"></a>
using </td><td class="memItemRight" valign="bottom"><b>allocator_type</b> = <a class="el" href="group__core.html#gaf1ce941b1306a592d4ebba1167fd98aa">make_block_allocator_t</a>< BlockOrRawAllocator ></td></tr>
<tr class="separator:a7fd26a8539389ffa2a4b1d1a7b6b839c"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:aa747aaa2496b4dec2049ea2165e65cd9"><td class="memItemLeft" align="right" valign="top">using </td><td class="memItemRight" valign="bottom"><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#aa747aaa2496b4dec2049ea2165e65cd9">marker</a> = FOONATHAN_IMPL_DEFINED(detail::stack_marker)</td></tr>
<tr class="memdesc:aa747aaa2496b4dec2049ea2165e65cd9"><td class="mdescLeft"> </td><td class="mdescRight">The marker type that is used for unwinding. <a href="classfoonathan_1_1memory_1_1memory__stack.html#aa747aaa2496b4dec2049ea2165e65cd9">More...</a><br /></td></tr>
<tr class="separator:aa747aaa2496b4dec2049ea2165e65cd9"><td class="memSeparator" colspan="2"> </td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="pub-methods"></a>
Member Functions</h2></td></tr>
<tr class="memitem:ab31c164183f69bc08896cfc4a8e5e8e7"><td class="memTemplParams" colspan="2">template<typename... Args> </td></tr>
<tr class="memitem:ab31c164183f69bc08896cfc4a8e5e8e7"><td class="memTemplItemLeft" align="right" valign="top"> </td><td class="memTemplItemRight" valign="bottom"><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#ab31c164183f69bc08896cfc4a8e5e8e7">memory_stack</a> (std::size_t block_size, Args &&... args)</td></tr>
<tr class="separator:ab31c164183f69bc08896cfc4a8e5e8e7"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a25a97fd86cd1ca7b24d7853c737824bb"><td class="memItemLeft" align="right" valign="top">void * </td><td class="memItemRight" valign="bottom"><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#a25a97fd86cd1ca7b24d7853c737824bb">allocate</a> (std::size_t size, std::size_t alignment)</td></tr>
<tr class="separator:a25a97fd86cd1ca7b24d7853c737824bb"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a859a385b3dc6459e9b819334a2fd10ab"><td class="memItemLeft" align="right" valign="top">void * </td><td class="memItemRight" valign="bottom"><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#a859a385b3dc6459e9b819334a2fd10ab">try_allocate</a> (std::size_t size, std::size_t alignment) noexcept</td></tr>
<tr class="separator:a859a385b3dc6459e9b819334a2fd10ab"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:aefe61fb94b49aa0aaaadd752f052adbe"><td class="memItemLeft" align="right" valign="top"><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#aa747aaa2496b4dec2049ea2165e65cd9">marker</a> </td><td class="memItemRight" valign="bottom"><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#aefe61fb94b49aa0aaaadd752f052adbe">top</a> () const noexcept</td></tr>
<tr class="separator:aefe61fb94b49aa0aaaadd752f052adbe"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a9f30af46c3d77066c680388109be2321"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#a9f30af46c3d77066c680388109be2321">unwind</a> (<a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#aa747aaa2496b4dec2049ea2165e65cd9">marker</a> m) noexcept</td></tr>
<tr class="separator:a9f30af46c3d77066c680388109be2321"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:ad9e4af5032d71179d3abf04db463f791"><td class="memItemLeft" align="right" valign="top">void </td><td class="memItemRight" valign="bottom"><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#ad9e4af5032d71179d3abf04db463f791">shrink_to_fit</a> () noexcept</td></tr>
<tr class="separator:ad9e4af5032d71179d3abf04db463f791"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a97da77ca5a46e5e3088d6c0637b52af7"><td class="memItemLeft" align="right" valign="top">std::size_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#a97da77ca5a46e5e3088d6c0637b52af7">capacity_left</a> () const noexcept</td></tr>
<tr class="separator:a97da77ca5a46e5e3088d6c0637b52af7"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:af4fe037332aabd13253517d22394da73"><td class="memItemLeft" align="right" valign="top">std::size_t </td><td class="memItemRight" valign="bottom"><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#af4fe037332aabd13253517d22394da73">next_capacity</a> () const noexcept</td></tr>
<tr class="separator:af4fe037332aabd13253517d22394da73"><td class="memSeparator" colspan="2"> </td></tr>
<tr class="memitem:a3ae445687ecb4a037b542ede5c6f48ac"><td class="memItemLeft" align="right" valign="top">allocator_type & </td><td class="memItemRight" valign="bottom"><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#a3ae445687ecb4a037b542ede5c6f48ac">get_allocator</a> () noexcept</td></tr>
<tr class="separator:a3ae445687ecb4a037b542ede5c6f48ac"><td class="memSeparator" colspan="2"> </td></tr>
</table>
<h2 class="groupheader">Typedefs</h2>
<a id="aa747aaa2496b4dec2049ea2165e65cd9"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa747aaa2496b4dec2049ea2165e65cd9">◆ </a></span>marker</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">using <a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#aa747aaa2496b4dec2049ea2165e65cd9">marker</a> = FOONATHAN_IMPL_DEFINED(detail::stack_marker)</td>
</tr>
</table>
</div><div class="memdoc">
<p>The marker type that is used for unwinding. </p>
<p>The exact type is implementation defined, it is only required that it is efficiently copyable and has all the comparision operators defined for two markers on the same stack. Two markers are equal, if they are copies or created from two <code>top()</code> calls without a call to <code>unwind()</code> or <code>allocate()</code>. A marker <code>a</code> is less than marker <code>b</code>, if after <code>a</code> was obtained, there was one or more call to <code>allocate()</code> and no call to <code>unwind()</code>. </p>
</div>
</div>
<h2 class="groupheader">Constructors</h2>
<a id="ab31c164183f69bc08896cfc4a8e5e8e7"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ab31c164183f69bc08896cfc4a8e5e8e7">◆ </a></span>memory_stack()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html">memory_stack</a> </td>
<td>(</td>
<td class="paramtype">std::size_t </td>
<td class="paramname"><em>block_size</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">Args &&... </td>
<td class="paramname"><em>args</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">explicit</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<dl class="section user"><dt>Effects:</dt><dd>Creates it with a given initial block size and and other constructor arguments for the <a href="md_doc_concepts.html#concept_blockallocator">BlockAllocator</a>. It will allocate the first block and sets the top to its beginning. </dd></dl>
</div>
</div>
<h2 class="groupheader">Member Functions</h2>
<a id="a25a97fd86cd1ca7b24d7853c737824bb"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a25a97fd86cd1ca7b24d7853c737824bb">◆ </a></span>allocate()</h2>
<div class="memitem">
<div class="memproto">
<table class="memname">
<tr>
<td class="memname">void* allocate </td>
<td>(</td>
<td class="paramtype">std::size_t </td>
<td class="paramname"><em>size</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">std::size_t </td>
<td class="paramname"><em>alignment</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</div><div class="memdoc">
<dl class="section user"><dt>Effects:</dt><dd>Allocates a memory block of given size and alignment. It simply moves the top marker. If there is not enough space on the current memory block, a new one will be allocated by the <a href="md_doc_concepts.html#concept_blockallocator">BlockAllocator</a> or taken from a cache and used for the allocation. </dd></dl>
<dl class="section user"><dt>Returns:</dt><dd>A <a href="md_doc_concepts.html#concept_node">node</a> with given size and alignment. </dd></dl>
<dl class="section user"><dt>Throws:</dt><dd>Anything thrown by the <a href="md_doc_concepts.html#concept_blockallocator">BlockAllocator</a> on growth or <a class="el" href="classfoonathan_1_1memory_1_1bad__allocation__size.html">bad_allocation_size</a> if <code>size</code> is too big. </dd></dl>
<dl class="section user"><dt>Requires:</dt><dd><code>size</code> and <code>alignment</code> must be valid. </dd></dl>
</div>
</div>
<a id="a859a385b3dc6459e9b819334a2fd10ab"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a859a385b3dc6459e9b819334a2fd10ab">◆ </a></span>try_allocate()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void* try_allocate </td>
<td>(</td>
<td class="paramtype">std::size_t </td>
<td class="paramname"><em>size</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">std::size_t </td>
<td class="paramname"><em>alignment</em> </td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">noexcept</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<dl class="section user"><dt>Effects:</dt><dd>Allocates a memory block of given size and alignment, similar to <a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#a25a97fd86cd1ca7b24d7853c737824bb">allocate()</a>. But it does not attempt a growth if the arena is empty. </dd></dl>
<dl class="section user"><dt>Returns:</dt><dd>A <a href="md_doc_concepts.html#concept_node">node</a> with given size and alignment or <code>nullptr</code> if there wasn't enough memory available. </dd></dl>
</div>
</div>
<a id="aefe61fb94b49aa0aaaadd752f052adbe"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aefe61fb94b49aa0aaaadd752f052adbe">◆ </a></span>top()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname"><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#aa747aaa2496b4dec2049ea2165e65cd9">marker</a> top </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> const</td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">noexcept</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<dl class="section user"><dt>Returns:</dt><dd>A marker to the current top of the stack. </dd></dl>
</div>
</div>
<a id="a9f30af46c3d77066c680388109be2321"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a9f30af46c3d77066c680388109be2321">◆ </a></span>unwind()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void unwind </td>
<td>(</td>
<td class="paramtype"><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#aa747aaa2496b4dec2049ea2165e65cd9">marker</a> </td>
<td class="paramname"><em>m</em></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">noexcept</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<dl class="section user"><dt>Effects:</dt><dd>Unwinds the stack to a certain marker position. This sets the top pointer of the stack to the position described by the marker and has the effect of deallocating all memory allocated since the marker was obtained. If any memory blocks are unused after the operation, they are not deallocated but put in a cache for later use, call <a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#ad9e4af5032d71179d3abf04db463f791">shrink_to_fit()</a> to actually deallocate them. </dd></dl>
<dl class="section user"><dt>Requires:</dt><dd>The marker must point to memory that is still in use and was the whole time, i.e. it must have been pointed below the top at all time. </dd></dl>
</div>
</div>
<a id="ad9e4af5032d71179d3abf04db463f791"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ad9e4af5032d71179d3abf04db463f791">◆ </a></span>shrink_to_fit()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void shrink_to_fit </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">noexcept</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<dl class="section user"><dt>Effects:</dt><dd><a class="el" href="classfoonathan_1_1memory_1_1memory__stack.html#a9f30af46c3d77066c680388109be2321">unwind()</a> does not actually do any deallocation of blocks on the <a href="md_doc_concepts.html#concept_blockallocator">BlockAllocator</a>, unused memory is stored in a cache for later reuse. This function clears that cache. </dd></dl>
</div>
</div>
<a id="a97da77ca5a46e5e3088d6c0637b52af7"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a97da77ca5a46e5e3088d6c0637b52af7">◆ </a></span>capacity_left()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">std::size_t capacity_left </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> const</td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">noexcept</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<dl class="section user"><dt>Returns:</dt><dd>The amount of memory remaining in the current block. This is the number of bytes that are available for allocation before the cache or <a href="md_doc_concepts.html#concept_blockallocator">BlockAllocator</a> needs to be used. </dd></dl>
</div>
</div>
<a id="af4fe037332aabd13253517d22394da73"></a>
<h2 class="memtitle"><span class="permalink"><a href="#af4fe037332aabd13253517d22394da73">◆ </a></span>next_capacity()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">std::size_t next_capacity </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td> const</td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">noexcept</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<dl class="section user"><dt>Returns:</dt><dd>The size of the next memory block after the current block is exhausted and the arena grows. This function just forwards to the <a class="el" href="classfoonathan_1_1memory_1_1memory__arena.html">memory_arena</a>. </dd></dl>
<dl class="section note"><dt>Note</dt><dd>All of it is available for the stack to use, but due to fences and alignment buffers, this may not be the exact amount of memory usable for the user. </dd></dl>
</div>
</div>
<a id="a3ae445687ecb4a037b542ede5c6f48ac"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a3ae445687ecb4a037b542ede5c6f48ac">◆ </a></span>get_allocator()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">allocator_type& get_allocator </td>
<td>(</td>
<td class="paramname"></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">noexcept</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<dl class="section user"><dt>Returns:</dt><dd>A reference to the <a href="md_doc_concepts.html#concept_blockallocator">BlockAllocator</a> used for managing the arena. </dd></dl>
<dl class="section user"><dt>Requires:</dt><dd>It is undefined behavior to move this allocator out into another object. </dd></dl>
</div>
</div>
</div><!-- contents -->
<!-- HTML footer for doxygen 1.8.16-->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.18
</small></address>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。