2
0
mirror of https://github.com/boostorg/pool.git synced 2026-01-26 06:42:25 +00:00
Files
pool/doc/interfaces/singleton_pool.html
Beman Dawes 0a122496e1 Initial commit
[SVN r9503]
2001-03-08 20:44:22 +00:00

157 lines
6.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>Singleton Pool</TITLE>
<LINK HREF="../pool.css" REL="stylesheet" TYPE="text/css">
</HEAD>
<BODY>
<IMG SRC="../../../../c++boost.gif" WIDTH=276 HEIGHT=86 ALT="C++ Boost">
<H1 ALIGN=CENTER>Singleton Pool</H1>
<P>
<H2>Introduction</H2>
<P>
singleton_pool.hpp provides a template class <SPAN CLASS="code">singleton_pool</SPAN>, which provides access to a <SPAN CLASS="code">pool</SPAN> as a singleton object. For information on other pool-based interfaces, see <A HREF="../interfaces.html">the other pool interfaces</A>.
<P>
<H2>Synopsis</H2>
<PRE CLASS="code">template &lt;typename Tag, unsigned RequestedSize,
typename UserAllocator = default_user_allocator_new_delete&gt;
struct singleton_pool
{
public:
typedef Tag tag;
typedef UserAllocator user_allocator;
typedef typename pool&lt;UserAllocator&gt;::size_type size_type;
typedef typename pool&lt;UserAllocator&gt;::difference_type difference_type;
static const unsigned requested_size = RequestedSize;
private:
static pool&lt;size_type&gt; p; // exposition only!
singleton_pool();
public:
static bool is_from(void * ptr);
static void * malloc();
static void * ordered_malloc();
static void * ordered_malloc(size_type n);
static void free(void * ptr);
static void ordered_free(void * ptr);
static void free(void * ptr, std::size_t n);
static void ordered_free(void * ptr, size_type n);
static bool release_memory();
static bool purge_memory();
};</PRE>
<P>
<H2>Notes</H2>
<P>
The underlying pool <SPAN CLASS="code">p</SPAN> referenced by the static functions in <SPAN CLASS="code">singleton_pool</SPAN> is actually declared in a way that it is:
<UL>
<LI>Thread-safe if there is only one thread running before main() begins and after main() ends -- all of the static functions of <SPAN CLASS="code">singleton_pool</SPAN> synchronize their access to <SPAN CLASS="code">p</SPAN>.</LI>
<LI>Guaranteed to be constructed before it is used -- thus, the simple static object in the synopsis above would actually be an incorrect implementation. The actual <A HREF="../implementation/singleton_pool.html">implementation</A> to guarantee this is considerably more complicated.
</UL>
<P>
Note that a different underlying pool <SPAN CLASS="code">p</SPAN> exists for each different set of template parameters, including <A HREF="../implementation/singleton_pool.html">implementation-specific ones</A>.
<P>
<H2>Template Parameters</H2>
<P>
<H3>Tag</H3>
<P>
The <SPAN CLASS="code">Tag</SPAN> template parameter allows different unbounded sets of singleton pools to exist. For example, the <A HREF="pool_alloc.html">pool allocators</A> use two tag classes to ensure that the two different allocator types never share the same underlying singleton pool.
<P>
<SPAN CLASS="code">Tag</SPAN> is never actually used by <SPAN CLASS="code">singleton_pool</SPAN>.
<P>
<H3>RequestedSize</H3>
<P>
The requested size of memory chunks to allocate. This is passed as a constructor parameter to the underlying <SPAN CLASS="code">pool</SPAN>. Must be greater than 0.
<P>
<H3>UserAllocator</H3>
<P>
Defines the method that the underlying <SPAN CLASS="code">pool</SPAN> will use to allocate memory from the system. See <A HREF="user_allocator.html">User Allocators</A> for details.
<P>
<H2>Semantics</H2>
<P>
<TABLE BORDER ALIGN=CENTER>
<CAPTION><EM>Symbol Table</EM></CAPTION>
<TR><TH>Symbol<TH>Meaning
<TR><TD CLASS="code">SingletonPool<TD CLASS="code">singleton_pool&lt;Tag, RequestedSize, UserAllocator&gt;
<TR><TD CLASS="code">chunk<TD>value of type <SPAN CLASS="code">void *</SPAN>
<TR><TD CLASS="code">n<TD>value of type <SPAN CLASS="code">size_type</SPAN>
</TABLE>
<P>
<TABLE BORDER ALIGN=CENTER>
<CAPTION><EM>Typedefs/Static Const Values</EM></CAPTION>
<TR><TH>Expression<TH>Type/Value
<TR><TD CLASS="code">SingletonPool::tag<TD CLASS="code">Tag
<TR><TD CLASS="code">SingletonPool::user_allocator<TD CLASS="code">UserAllocator
<TR><TD CLASS="code">SingletonPool::size_type<TD CLASS="code">pool&lt;UserAllocator&gt;::size_type
<TR><TD CLASS="code">SingletonPool::difference_type<TD CLASS="code">pool&lt;UserAllocator&gt;::difference_type
<TR><TD CLASS="code">SingletonPool::requested_size<TD CLASS="code">RequestedSize
</TABLE>
<P>
<TABLE BORDER ALIGN=CENTER>
<CAPTION><EM>Functions</EM></CAPTION>
<TR><TH>Expression<TH>Return Type<TH>Semantic Equivalent
<TR><TD CLASS="code">SingletonPool::is_from(chunk)<TD CLASS="code">bool<TD><SPAN CLASS="code">SingletonPool::p.is_from(chunk);</SPAN> synchronized
<TR><TD CLASS="code">SingletonPool::malloc()<TD CLASS="code">void *<TD><SPAN CLASS="code">SingletonPool::p.malloc();</SPAN> synchronized
<TR><TD CLASS="code">SingletonPool::ordered_malloc(n)<TD CLASS="code">void *<TD><SPAN CLASS="code">SingletonPool::p.ordered_malloc(n);</SPAN> synchronized
<TR><TD CLASS="code">SingletonPool::free(chunk)<TD CLASS="code">void<TD><SPAN CLASS="code">SingletonPool::p.free(chunk);</SPAN> synchronized
<TR><TD CLASS="code">SingletonPool::ordered_free(chunk)<TD CLASS="code">void<TD><SPAN CLASS="code">SingletonPool::p.ordered_free(chunk);</SPAN> synchronized
<TR><TD CLASS="code">SingletonPool::free(chunk, n)<TD CLASS="code">void<TD><SPAN CLASS="code">SingletonPool::p.free(chunk, n);</SPAN> synchronized
<TR><TD CLASS="code">SingletonPool::ordered_free(chunk, n)<TD CLASS="code">void<TD><SPAN CLASS="code">SingletonPool::p.ordered_free(chunk, n);</SPAN> synchronized
<TR><TD CLASS="code">SingletonPool::release_memory()<TD CLASS="code">bool<TD><SPAN CLASS="code">SingletonPool::p.release_memory();</SPAN> synchronized
<TR><TD CLASS="code">SingletonPool::purge_memory()<TD CLASS="code">bool<TD><SPAN CLASS="code">SingletonPool::p.purge_memory();</SPAN> synchronized
</TABLE>
<P>
For more information on the semantics of these functions, see the <A HREF="pool.html">pool interface</A>.
<P>
<H2>Symbols</H2>
<P>
<UL>
<LI>boost::singleton_pool</LI>
</UL>
<P>
<H2><A HREF="../implementation/singleton_pool.html">Implementation Details</A></H2>
<P>
<HR>
<P>
Copyright &copy; 2000, 2001 Stephen Cleary (<A HREF="mailto:shammah@voyager.net">shammah@voyager.net</A>)
<P>
This file can be redistributed and/or modified under the terms found in <A HREF="../copyright.html">copyright.html</A>
<P>
This software and its documentation is provided &quot;as is&quot; without express or implied warranty, and with no claim as to its suitability for any purpose.
</BODY>
</HTML>