1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<HTML>
<HEAD>
<TITLE>object_pool - Boost Object Pool Allocator</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>object_pool - Boost Object Pool Allocator</H1>
<P>
<H2>Introduction</H2>
<P>
object_pool.hpp provides a template type that can be used for fast and efficient memory allocation. It also provides automatic destruction of non-deallocated objects. 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 <typename ElementType, typename UserAllocator = default_user_allocator_new_delete>
class object_pool
{
private:
object_pool(const object_pool &);
void operator=(const object_pool &);
public:
typedef ElementType element_type;
typedef UserAllocator user_allocator;
typedef typename pool<UserAllocator>::size_type size_type;
typedef typename pool<UserAllocator>::difference_type difference_type;
object_pool();
~object_pool();
element_type * malloc();
void free(element_type * p);
bool is_from(element_type * p) const;
element_type * construct();
// other construct() functions
void destroy(element_type * p);
};</PRE>
<P>
<H2>Template Parameters</H2>
<P>
<H3>ElementType</H3>
<P>
The template parameter is the type of object to allocate/deallocate. It must have a non-throwing destructor.
<P>
<H3>UserAllocator</H3>
<P>
Defines the method that the underlying Pool 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">ObjectPool<TD><SPAN CLASS="code">object_pool<ElementType, UserAllocator></SPAN>
<TR><TD CLASS="code">t<TD>value of type <SPAN CLASS="code">ObjectPool</SPAN>
<TR><TD CLASS="code">u<TD>value of type <SPAN CLASS="code">const ObjectPool</SPAN>
<TR><TD CLASS="code">p<TD>value of type <SPAN CLASS="code">ElementType *</SPAN>
</TABLE>
<P>
<TABLE BORDER ALIGN=CENTER>
<CAPTION><EM>Typedefs</EM></CAPTION>
<TR><TH>Expression<TH>Type
<TR><TD CLASS="code">ObjectPool::element_type<TD CLASS="code">ElementType
<TR><TD CLASS="code">ObjectPool::user_allocator<TD CLASS="code">UserAllocator
<TR><TD CLASS="code">ObjectPool::size_type<TD CLASS="code">pool<UserAllocator>::size_type
<TR><TD CLASS="code">ObjectPool::difference_type<TD CLASS="code">pool<UserAllocator>::difference_type
</TABLE>
<P>
<TABLE BORDER ALIGN=CENTER>
<CAPTION><EM>Constructors, Destructors, and Testing</EM></CAPTION>
<TR><TH>Expression<TH>Return Type<TH>Notes
<TR><TD CLASS="code">ObjectPool()<TD>not used<TD>Constructs a new empty <SPAN CLASS="code">ObjectPool</SPAN>
<TR><TD CLASS="code">(&t)->~ObjectPool()<TD>not used<TD>Destructs the <SPAN CLASS="code">ObjectPool</SPAN>; <SPAN CLASS="code">~ElementType()</SPAN> is called for each allocated ElementType that has not been deallocated. O(N).
<TR><TD CLASS="code">u.is_from(p)<TD CLASS="code">bool<TD>Returns <SPAN CLASS="code">true</SPAN> if <SPAN CLASS="code">p</SPAN> was allocated from <SPAN CLASS="code">u</SPAN> or may be returned as the result of a future allocation from <SPAN CLASS="code">u</SPAN>. Returns <SPAN CLASS="code">false</SPAN> if <SPAN CLASS="code">p</SPAN> was allocated from some other pool or may be returned as the result of a future allocation from some other pool. Otherwise, the return value is meaningless; note that this function may <STRONG>not</STRONG> be used to reliably test random pointer values.
</TABLE>
<P>
<TABLE BORDER ALIGN=CENTER>
<CAPTION><EM>Allocation and Deallocation</EM></CAPTION>
<TR><TH>Expression<TH>Return Type<TH>Pre-Condition<TH>Semantic Equivalence<TH>Notes
<TR><TD CLASS="code">t.malloc()<TD CLASS="code">ElementType *<TD><TD><TD>Allocates memory that can hold an object of type <SPAN CLASS="code">ElementType</SPAN>. If out of memory, returns <SPAN CLASS="code">0</SPAN>. Amortized O(1).
<TR><TD CLASS="code">t.free(p)<TD>not used<TD><SPAN CLASS="code">p</SPAN> must have been previously allocated from <SPAN CLASS="code">t</SPAN><TD><TD>Deallocates a chunk of memory. Note that <SPAN CLASS="code">p</SPAN> may not be <SPAN CLASS="code">0</SPAN>. Note that the destructor for <SPAN CLASS="code">p</SPAN> is not called. O(N).
<TR><TD CLASS="code">t.construct(???)<TD CLASS="code">ElementType *<TD><SPAN CLASS="code">ElementType</SPAN> must have a constructor matching <SPAN CLASS="code">???</SPAN>; the number of parameters given must not exceed what is supported through <A HREF="../implementation/pool_construct.html">pool_construct</A><TD><TD>Allocates and initializes an object of type <SPAN CLASS="code">ElementType</SPAN>. If out of memory, returns <SPAN CLASS="code">0</SPAN>. Amortized O(1).
<TR><TD CLASS="code">t.destroy(p)<TD>not used<TD><SPAN CLASS="code">p</SPAN> must have been previously allocated from <SPAN CLASS="code">t</SPAN><TD CLASS="code">p->~ElementType(); t.free(p);<TD>
</TABLE>
<P>
<H2>Symbols</H2>
<P>
<UL>
<LI>boost::object_pool</LI>
</UL>
<P>
<H2><A HREF="../implementation/object_pool.html">Implementation Details</A></H2>
<P>
<HR>
<P>
Copyright © 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 "as is" without express or implied warranty, and with no claim as to its suitability for any purpose.
</BODY>
</HTML>
|