diff --git a/gtsam/base/FastList.h b/gtsam/base/FastList.h index 1b84adfed..aa1ab24e8 100644 --- a/gtsam/base/FastList.h +++ b/gtsam/base/FastList.h @@ -50,9 +50,18 @@ public: /** Copy constructor from another FastList */ FastList(const FastList& x) : Base(x) {} - /** Copy constructor from the base map class */ + /** Copy constructor from the base list class */ FastList(const Base& x) : Base(x) {} + /** Copy constructor from a standard STL container */ + FastList(const std::list& 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; diff --git a/gtsam/base/FastSet.h b/gtsam/base/FastSet.h index 4c6e31d4e..123a8bb31 100644 --- a/gtsam/base/FastSet.h +++ b/gtsam/base/FastSet.h @@ -66,11 +66,20 @@ public: Base(x) { } - /** Copy constructor from the base map class */ + /** Copy constructor from the base set class */ FastSet(const Base& x) : Base(x) { } + /** Copy constructor from a standard STL container */ + FastSet(const std::set& 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::insert(x.begin(), x.end()); + } + /** Print to implement Testable */ void print(const std::string& str = "") const { FastSetTestableHelper::print(*this, str); }