add a note
authorChris Lattner <sabre@nondot.org>
Mon, 5 Feb 2007 06:30:51 +0000 (06:30 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 5 Feb 2007 06:30:51 +0000 (06:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33904 91177308-0d34-0410-b5e6-96231b3b80d8

docs/ProgrammersManual.html

index 1d5ad0e82c0d8319fa5dea47da7e8f80c5f5ee46..c4fedbf5d7bd60a67ffc228b76fabd9d48024453 100644 (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>
 
 <!-- _______________________________________________________________________ -->