⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 allocators.html

📁 指导程序员合理、高效的进行标准模板库编程。
💻 HTML
字号:
<HTML>
<HEAD>
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
   <META NAME="Author" CONTENT="Zafir Anjum">
   <TITLE>MFC Programmer's SourceBook : STL Programmer's Guide</TITLE>
    <META name="description" 
     content="A freely available implementation 
     of the C++ Standard Template Library, including 
     hypertext documentation.">
	<META name="keywords" 
	content="generic programming, STL, standard template library">
</HEAD>

<SCRIPT LANGUAGE="JavaScript"><!--
var adcategory = "cpp";
// -->
</SCRIPT>
<body background="../../fancyhome/back.gif" bgcolor="#FFFFFF" >
<SCRIPT LANGUAGE="JavaScript"><!--
var nfrm = location.href.indexOf("_nfrm_");
var validframes = (top.frames.length > 0 && top.frames['ad'] && top.frames['logo'] );
var random = Math.random();

if( !validframes && nfrm == -1 )
{
	var dclkPage = "www.codeguru.com/";
	if( self.adcategory )
		dclkPage += adcategory;
	else
		dclkPage += "mfc";
	document.write('<nolayer><center>');
	document.write('<iframe src="http://ad.doubleclick.net/adi/' + dclkPage + ';ord='
	 + random + '" width=470 height=62 marginwidth=0 marginheight=0 hspace=0 vspace=0 '
	 + 'frameborder=0 scrolling=no bordercolor="#000000">');
	document.write('<a href="http://ad.doubleclick.net/jump/' + dclkPage + ';ord='
	 + random + '">');
	document.write('<img src="http://ad.doubleclick.net/ad/' + dclkPage + ';ord='
	 + random + '" height=60 width=468>' + '</a>');
	document.write('</iframe>');
	document.write('</center></nolayer>');
	document.write('<layer  src="http://ad.doubleclick.net/adl/' + dclkPage + 
	 ';ord=' + random + '"></layer>');
	document.write('<ilayer visibility=hide width=468 height=83></ilayer>');
}


//		top.location = "/show.cgi?" + adcategory + "=" + location.pathname;


// -->
</SCRIPT>
<noscript>
<p align="center">
<a href="http://ad.doubleclick.net/jump/www.codeguru.com/cpp;ord=Nupb99FCY34AAHpQUds">
<img src="http://ad.doubleclick.net/ad/www.codeguru.com/cpp;ord=Nupb99FCY34AAHpQUds"></a>
</p>
</noscript>





<BR Clear>
<H1>Allocators</H1>

<Table CellPadding=0 CellSpacing=0 width=100%>
<TR>
<TD Align=left><Img src = "allocators.gif" Alt=""   WIDTH = "194"  HEIGHT = "38" ></TD>
<TD Align=right><Img src = "overview.gif" Alt=""   WIDTH = "194"  HEIGHT = "38" ></TD>
</TR>
<TR>
<TD Align=left VAlign=top><b>Category</b>: allocators</TD>
<TD Align=right VAlign=top><b>Component type</b>: overview</TD>
</TR>
</Table>

<h3>Summary</h3>
Allocators encapsulate allocation and deallocation of memory.  They
provide a low-level interface that permits efficient allocation of 
many small objects; different allocator types represent different
schemes for memory management.
<P>
Note that allocators simply allocate and deallocate memory, as opposed
to creating and destroying objects.  The STL also includes several
low-level algorithms for manipulating uninitialized memory.
<P>
Note also that allocators do not attempt to encapsulate multiple
memory models.  The C++ language only defines a single memory model
(the difference of two pointers, for example, is always <tt>ptrdiff_t</tt>),
and this memory model is the only one that allocators support. 
<i>This is a major change from the definition of allocators in the
original STL.</i> <A href="#1">[1]</A>
<h3>Description</h3>
The details of the allocator interface are still subject to change,
and we do not guarantee that specific member functions will remain in
future versions.  You should think of an allocator as a &quot;black box&quot;.
That is, you may select a container's memory allocation strategy by
instantiating the container template with a particular allocator <A href="#2">[2]</A>,
but you should not make any assumptions about how the container 
actually uses the allocator.  
<P>
The available allocators are as follows.  In most cases you shouldn't
have to worry about the distinction: the default allocator, <tt>alloc</tt>,
is usually the best choice.
<Table border>
<TR>
<TD VAlign=top>
<tt>alloc</tt>
</TD>
<TD VAlign=top>
The default allocator.  It is thread-safe, and usually has the best
   performance characteristics.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>pthread_alloc</tt>
</TD>
<TD VAlign=top>
A thread-safe allocator that uses a different memory pool for
   each thread;  you can only 
   use <tt>pthread_alloc</tt> if your operating system provides pthreads.
   <tt>Pthread_alloc</tt> is usually faster than <tt>alloc</tt>, especially on
   multiprocessor systems.  It can, however, cause
   resource fragmentation: memory deallocated in one
   thread is not available for use by other threads.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>single_client_alloc</tt>
</TD>
<TD VAlign=top>
A fast but thread-unsafe allocator.  In programs that only have
   one thread, this allocator might be faster than <tt>alloc</tt>.
</TD>
</TR>
<TR>
<TD VAlign=top>
<tt>malloc_alloc</tt>
</TD>
<TD VAlign=top>
An allocator that simply uses the standard library function <tt>malloc</tt>.
   It is thread-safe but slow; the main reason why you might
   sometimes want to use it is to get more useful information from
   bounds-checking or leak-detection tools while you are debugging.
</TD>
</tr>
</table>
<h3>Examples</h3>
<pre>
vector&lt;double&gt; V(100, 5.0);     // Uses the default allocator.
vector&lt;double, single_client_alloc&gt; local(V.begin(), V.end());
</pre>
<h3>Concepts</h3>
<UL>
<LI>
Allocator
</UL>
<h3>Types</h3>
<UL>
<LI>
<tt>alloc</tt>
<LI>
<tt>pthread_alloc</tt>
<LI>
<tt>single_client_alloc</tt>
<LI>
<tt>malloc_alloc</tt>
<LI>
<tt><A href="raw_storage_iterator.html">raw_storage_iterator</A></tt>
</UL>
<h3>Functions</h3>
<UL>
<LI>
<tt><A href="construct.html">construct</A></tt>
<LI>
<tt><A href="destroy.html">destroy</A></tt>
<LI>
<tt><A href="uninitialized_copy.html">uninitialized_copy</A></tt>
<LI>
<tt><A href="uninitialized_fill.html">uninitialized_fill</A></tt>
<LI>
<tt><A href="uninitialized_fill_n.html">uninitialized_fill_n</A></tt>
<LI>
<tt><A href="get_temporary_buffer.html">get_temporary_buffer</A></tt>
<LI>
<tt><A href="return_temporary_buffer.html">return_temporary_buffer</A></tt>
</UL>
<h3>Notes</h3>
<P><A name="1">[1]</A>
The reason for this change is that the new interface reduces
memory fragmentation, and that it allows an implementation that
is both efficient and thread-safe.
<P><A name="2">[2]</A>
Different containers may use different allocators.  You might,
for example, have some containers that use the default allocator
<tt>alloc</tt> and others that use <tt>pthread_alloc</tt>.  Note, however, that
<tt>vector&lt;int&gt;</tt> and <tt>vector&lt;int, pthread_alloc&gt;</tt> are distinct types.
<h3>See also</h3>

<HR SIZE="6"> <FONT SIZE="-2"> Copyright &copy; 1996 Silicon Graphics, Inc.
<HR>
<TABLE BORDER=0 WIDTH="100%" >
<TR>
<TD WIDTH="33%"><FONT SIZE=-1><A HREF="index.html" >
STL</A></FONT></TD>

<TD WIDTH="33%">
<CENTER><FONT SIZE=-2>&copy; Copyright 1997-1998 CodeGuru</FONT>&nbsp;</CENTER>
</TD>

<TD WIDTH="34%">
<DIV ALIGN=right><FONT SIZE=-1>Contact : <A HREF="mailto:webmaster@codeguru.com">webmaster@codeguru.com</A>&nbsp;</FONT></DIV>
</TD>
</TR>
</TABLE>
<SCRIPT LANGUAGE="JavaScript" ><!--
var adurl = "/cgi-bin/doubleclick.cgi?";

if( self.adcategory )
	adurl += adcategory;
else
	adurl += "mfc";

if( self.parent.norefreshad )
	parent.norefreshad = false;
else if( validframes )
	parent.frames['ad'].location = adurl;



if( !validframes && nfrm == -1)
{
	var dclkPage = "www.codeguru.com/";
	if( self.adcategory )
		dclkPage += adcategory;
	else 
		dclkPage += "mfc";
//	var random = Math.random();
	document.write('<nolayer><center>');
	document.write('<iframe src="http://ad.doubleclick.net/adi/' + dclkPage + ';ord='
	 + random + '" width=470 height=62 marginwidth=0 marginheight=0 hspace=0 vspace=0 '
	 + 'frameborder=0 scrolling=no bordercolor="#000000">');
	document.write('<a href="http://ad.doubleclick.net/jump/' + dclkPage + ';ord='
	 + random + '">');
	document.write('<img src="http://ad.doubleclick.net/ad/' + dclkPage + ';ord='
	 + random + '" height=60 width=468>' + '</a>');
	document.write('</iframe>');
	document.write('</center></nolayer>');
	document.write('<layer  src="http://ad.doubleclick.net/adl/' + dclkPage + 
	 ';ord=' + random + '"></layer>');
	document.write('<ilayer visibility=hide width=468 height=83></ilayer>');
}

// -->
</SCRIPT> 
<!-- SCRIPT LANGUAGE="JavaScript" SRC="/global/fscript.js">
//
</SCRIPT --> 

<noscript>
<p align="center">
<a href="http://ad.doubleclick.net/jump/www.codeguru.com/cpp;ord=Nupb99FCY34AAHpQUds">
<img src="http://ad.doubleclick.net/ad/www.codeguru.com/cpp;ord=Nupb99FCY34AAHpQUds"></a>
</p>
</noscript>





</BODY>
</HTML>


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -