1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00

add a note

llvm-svn: 33904
This commit is contained in:
Chris Lattner 2007-02-05 06:30:51 +00:00
parent b32cc501f5
commit 318e23e7fe

View File

@ -797,6 +797,33 @@ rarely be a benefit) or if you will be allocating many instances of the vector
itself (which would waste space for elements that aren't in the container).
vector is also useful when interfacing with code that expects vectors :).
</p>
<p>One worthwhile note about std::vector: avoid code like this:</p>
<div class="doc_code">
<pre>
for ( ... ) {
std::vector<foo> V;
use V;
}
</pre>
</div>
<p>Instead, write this as:</p>
<div class="doc_code">
<pre>
std::vector<foo> V;
for ( ... ) {
use V;
V.clear();
}
</pre>
</div>
<p>Doing so will save (at least) one heap allocation and free per iteration of
the loop.</p>
</div>
<!-- _______________________________________________________________________ -->