From 32d84765c8e9e6bcfd5a012ceb625d64c44a373b Mon Sep 17 00:00:00 2001
From: Chris Lattner
Date: Mon, 5 Feb 2007 06:30:51 +0000
Subject: add a note
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33904 91177308-0d34-0410-b5e6-96231b3b80d8
---
docs/ProgrammersManual.html | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
(limited to 'docs/ProgrammersManual.html')
diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html
index 1d5ad0e82c..c4fedbf5d7 100644
--- a/docs/ProgrammersManual.html
+++ b/docs/ProgrammersManual.html
@@ -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 :).
+
+One worthwhile note about std::vector: avoid code like this:
+
+
+
+for ( ... ) {
+ std::vector V;
+ use V;
+}
+
+
+
+Instead, write this as:
+
+
+
+std::vector V;
+for ( ... ) {
+ use V;
+ V.clear();
+}
+
+
+
+Doing so will save (at least) one heap allocation and free per iteration of
+the loop.
+
--
cgit v1.2.3-70-g09d2