From 7404f78bc1c6a7b7050d56527da675667c7b776f Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Thu, 10 Feb 2011 01:52:01 +0000 Subject: [PATCH] Added "FastVector", an std::vector using a boost pool_allocator --- gtsam/base/FastVector.h | 55 +++++++++++++++++++++++++++++++++++++++++ gtsam/base/Makefile.am | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 gtsam/base/FastVector.h diff --git a/gtsam/base/FastVector.h b/gtsam/base/FastVector.h new file mode 100644 index 000000000..00a9bb801 --- /dev/null +++ b/gtsam/base/FastVector.h @@ -0,0 +1,55 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file FastSet.h + * @brief A thin wrapper around std::vector that uses boost's pool_allocator. + * @author Richard Roberts + * @created Feb 9, 2011 + */ + +#pragma once + +#include +#include + +namespace gtsam { + +/** + * FastVector is a thin wrapper around std::vector that uses the boost + * pool_allocator instead of the default STL allocator. This is just a + * convenience to avoid having lengthy types in the code. Through timing, + * we've seen that the pool_allocator can lead to speedups of several + * percent. + */ +template +class FastVector: public std::vector > { + +public: + + typedef std::vector > Base; + + /** Default constructor */ + FastVector() {} + + /** Constructor from a range, passes through to base class */ + template + FastVector(INPUTITERATOR first, INPUTITERATOR last) : Base(first, last) {} + + /** Copy constructor from another FastSet */ + FastVector(const FastVector& x) : Base(x) {} + + /** Copy constructor from the base map class */ + FastVector(const Base& x) : Base(x) {} + +}; + +} diff --git a/gtsam/base/Makefile.am b/gtsam/base/Makefile.am index ba13e1641..4d10680f3 100644 --- a/gtsam/base/Makefile.am +++ b/gtsam/base/Makefile.am @@ -32,7 +32,7 @@ sources += LieVector.cpp check_PROGRAMS += tests/testLieVector tests/testLieScalar # Data structures -headers += BTree.h DSF.h FastMap.h FastSet.h FastList.h +headers += BTree.h DSF.h FastMap.h FastSet.h FastList.h FastVector.h sources += DSFVector.cpp check_PROGRAMS += tests/testBTree tests/testDSF tests/testDSFVector