From 30bb9e61ccac634fe92af29bcaff8de19892ffec Mon Sep 17 00:00:00 2001 From: Richard Roberts Date: Mon, 13 Feb 2012 20:27:59 +0000 Subject: [PATCH] Workaround for possible bug in pool allocator --- gtsam/base/FastVector.h | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/gtsam/base/FastVector.h b/gtsam/base/FastVector.h index cb08871d9..18af63006 100644 --- a/gtsam/base/FastVector.h +++ b/gtsam/base/FastVector.h @@ -50,14 +50,29 @@ public: /** Constructor from a range, passes through to base class */ template - explicit FastVector(INPUTITERATOR first, INPUTITERATOR last) : Base(first, last) {} + explicit FastVector(INPUTITERATOR first, INPUTITERATOR last) { + // This if statement works around a bug in boost pool allocator and/or + // STL vector where if the size is zero, the pool allocator will allocate + // huge amounts of memory. + if(first != last) + Base::assign(first, last); + } /** Copy constructor from another FastSet */ FastVector(const FastVector& x) : Base(x) {} - /** Copy constructor from the base map class */ + /** Copy constructor from the base class */ FastVector(const Base& x) : Base(x) {} + /** Copy constructor from a standard STL container */ + FastVector(const std::vector& x) { + // This if statement works around a bug in boost pool allocator and/or + // STL vector where if the size is zero, the pool allocator will allocate + // huge amounts of memory. + if(x.size() > 0) + Base::assign(x.begin(), x.end()); + } + private: /** Serialization function */ friend class boost::serialization::access;