mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
add a note
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33904 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -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).
|
itself (which would waste space for elements that aren't in the container).
|
||||||
vector is also useful when interfacing with code that expects vectors :).
|
vector is also useful when interfacing with code that expects vectors :).
|
||||||
</p>
|
</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>
|
</div>
|
||||||
|
|
||||||
<!-- _______________________________________________________________________ -->
|
<!-- _______________________________________________________________________ -->
|
||||||
|
Reference in New Issue
Block a user