mirror of
https://github.com/boostorg/pool.git
synced 2026-01-25 06:22:14 +00:00
91 lines
3.2 KiB
HTML
91 lines
3.2 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
|
<HTML>
|
|
<HEAD>
|
|
<TITLE>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>User Allocators</H1>
|
|
|
|
<P>
|
|
<H2>Introduction</H2>
|
|
|
|
<P>
|
|
Pool objects need to request memory blocks from the system, which the Pool then splits into chunks to allocate to the user. By specifying a <SPAN CLASS="code">UserAllocator</SPAN> template parameter to various Pool interfaces, users can control how those system memory blocks are allocated.
|
|
|
|
<P>
|
|
<H2>Semantics</H2>
|
|
|
|
<P>
|
|
<TABLE BORDER ALIGN=CENTER>
|
|
<CAPTION><EM>Symbol Table</EM></CAPTION>
|
|
<TR><TH>Symbol<TH>Meaning
|
|
<TR><TD CLASS="code">UserAllocator<TD>A User Allocator type
|
|
<TR><TD CLASS="code">block<TD>value of type <SPAN CLASS="code">char *</SPAN>
|
|
<TR><TD CLASS="code">n<TD>value of type <SPAN CLASS="code">UserAllocator::size_type</SPAN>
|
|
</TABLE>
|
|
|
|
<P>
|
|
<TABLE BORDER ALIGN=CENTER>
|
|
<CAPTION><EM>Typedefs</EM></CAPTION>
|
|
<TR><TH>Expression<TH>Type
|
|
<TR><TD CLASS="code">UserAllocator::size_type<TD>An unsigned integral type that can represent the size of the largest object to be allocated
|
|
<TR><TD CLASS="code">UserAllocator::difference_type<TD>A signed integral type that can represent the difference of any two pointers
|
|
</TABLE>
|
|
|
|
<P>
|
|
<TABLE BORDER ALIGN=CENTER>
|
|
<CAPTION><EM>Allocation and Deallocation</EM></CAPTION>
|
|
<TR><TH>Expression<TH>Return Type<TH>Pre-Condition/Notes
|
|
<TR><TD CLASS="code">UserAllocator::malloc(n)<TD CLASS="code">char *<TD>Attempts to allocate <SPAN CLASS="code">n</SPAN> bytes from the system. Returns 0 if out-of-memory.
|
|
<TR><TD CLASS="code">UserAllocator::free(block)<TD CLASS="code">void<TD><SPAN CLASS="code">block</SPAN> must have been previously returned from a call to <SPAN CLASS="code">UserAllocator::malloc</SPAN>.
|
|
</TABLE>
|
|
|
|
<P>
|
|
<H2>Provided Implementations</H2>
|
|
|
|
<P>
|
|
There are two <SPAN CLASS="code">UserAllocator</SPAN> classes provided. Both of them are in pool.hpp (see <A HREF="pool.html">pool</A>). The default value for the template parameter <SPAN CLASS="code">UserAllocator</SPAN> is always <SPAN CLASS="code">default_user_allocator_new_delete</SPAN>.
|
|
|
|
<P>
|
|
<H3>Synopsis</H3>
|
|
|
|
<PRE CLASS="code">struct default_user_allocator_new_delete
|
|
{
|
|
typedef std::size_t size_type;
|
|
typedef std::ptrdiff_t difference_type;
|
|
|
|
static char * malloc(const size_type bytes)
|
|
{ return new (std::nothrow) char[bytes]; }
|
|
static void free(char * const block)
|
|
{ delete [] block; }
|
|
};
|
|
|
|
struct default_user_allocator_malloc_free
|
|
{
|
|
typedef std::size_t size_type;
|
|
typedef std::ptrdiff_t difference_type;
|
|
|
|
static char * malloc(const size_type bytes)
|
|
{ return reinterpret_cast<char *>(std::malloc(bytes)); }
|
|
static void free(char * const block)
|
|
{ std::free(block); }
|
|
};</PRE>
|
|
|
|
<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> |