[llvm-commits] CVS: llvm/docs/ProgrammersManual.html

Chris Lattner sabre at nondot.org
Sun Feb 4 22:31:07 PST 2007



Changes in directory llvm/docs:

ProgrammersManual.html updated: 1.120 -> 1.121
---
Log message:

add a note


---
Diffs of the changes:  (+28 -1)

 ProgrammersManual.html |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletion(-)


Index: llvm/docs/ProgrammersManual.html
diff -u llvm/docs/ProgrammersManual.html:1.120 llvm/docs/ProgrammersManual.html:1.121
--- llvm/docs/ProgrammersManual.html:1.120	Sat Feb  3 18:00:26 2007
+++ llvm/docs/ProgrammersManual.html	Mon Feb  5 00:30:51 2007
@@ -797,6 +797,33 @@
 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>
 
 <!-- _______________________________________________________________________ -->
@@ -3170,7 +3197,7 @@
   <a href="mailto:dhurjati at cs.uiuc.edu">Dinakar Dhurjati</a> and
   <a href="mailto:sabre at nondot.org">Chris Lattner</a><br>
   <a href="http://llvm.org">The LLVM Compiler Infrastructure</a><br>
-  Last modified: $Date: 2007/02/04 00:00:26 $
+  Last modified: $Date: 2007/02/05 06:30:51 $
 </address>
 
 </body>






More information about the llvm-commits mailing list