From 318e23e7fe4c09f316891a2b7803f360f4834f57 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 5 Feb 2007 06:30:51 +0000 Subject: [PATCH] add a note llvm-svn: 33904 --- docs/ProgrammersManual.html | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/docs/ProgrammersManual.html b/docs/ProgrammersManual.html index 1d5ad0e82c0..c4fedbf5d7b 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.

+