summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-09-28 21:25:57 +0000
committerglisse <glisse@636b058d-ea47-450e-bf9e-a15bfbe3eedb>2015-09-28 21:25:57 +0000
commit41e6d3213b7d6c3d170239ae2fca24e5d19569c1 (patch)
tree7717f3a8f77763171c5c0975f869bac4f174da66
parentfb0a592e87816c30101c2a69e72b59e98d44c2fa (diff)
parent5dcc9dd4b14705b655c0129cf390c35a51b57dfe (diff)
Reintegrate branch pool.
Stop using boost::object_pool, which sucks. When coefficients are mpz_class, we could still gain time by recycling live cells instead of running the destructor, recycling the storage, and running the constructor again. git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/trunk@804 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: eef5f693411adafbdf45584462116b7e06ef1c3e
-rw-r--r--src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h10
-rw-r--r--src/common/include/gudhi/Simple_object_pool.h64
2 files changed, 69 insertions, 5 deletions
diff --git a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
index efe20151..5f399f1a 100644
--- a/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
+++ b/src/Persistent_cohomology/include/gudhi/Persistent_cohomology.h
@@ -25,12 +25,12 @@
#include <gudhi/Persistent_cohomology/Persistent_cohomology_column.h>
#include <gudhi/Persistent_cohomology/Field_Zp.h>
+#include <gudhi/Simple_object_pool.h>
#include <boost/tuple/tuple.hpp>
#include <boost/intrusive/set.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include <boost/intrusive/list.hpp>
-#include <boost/pool/object_pool.hpp>
#include <map>
#include <utility>
@@ -268,8 +268,8 @@ class Persistent_cohomology {
~Persistent_cohomology() {
// Clean the transversal lists
for (auto & transverse_ref : transverse_idx_) {
- // Release all the cells
- transverse_ref.second.row_->clear_and_dispose([&](Cell*p){cell_pool_.destroy(p);});
+ // Destruct all the cells
+ transverse_ref.second.row_->clear_and_dispose([&](Cell*p){p->~Cell();});
delete transverse_ref.second.row_;
}
}
@@ -764,8 +764,8 @@ class Persistent_cohomology {
std::vector<Persistent_interval> persistent_pairs_;
length_interval interval_length_policy;
- boost::object_pool<Column> column_pool_;
- boost::object_pool<Cell> cell_pool_;
+ Simple_object_pool<Column> column_pool_;
+ Simple_object_pool<Cell> cell_pool_;
};
/** @} */ // end defgroup persistent_cohomology
diff --git a/src/common/include/gudhi/Simple_object_pool.h b/src/common/include/gudhi/Simple_object_pool.h
new file mode 100644
index 00000000..fffcb2ef
--- /dev/null
+++ b/src/common/include/gudhi/Simple_object_pool.h
@@ -0,0 +1,64 @@
+/* This file is part of the Gudhi Library. The Gudhi library
+ * (Geometric Understanding in Higher Dimensions) is a generic C++
+ * library for computational topology.
+ *
+ * Author(s): Marc Glisse
+ *
+ * Copyright (C) 2015 INRIA Saclay - Ile de France
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <boost/pool/pool.hpp>
+#include <utility>
+
+namespace Gudhi {
+ /** \private
+ * This is a simpler version of boost::object_pool, that requires
+ * that users explicitly destroy all objects. This lets the
+ * performance scale much better, see
+ * https://svn.boost.org/trac/boost/ticket/3789 .
+ */
+template <class T>
+class Simple_object_pool : protected boost::pool<boost::default_user_allocator_malloc_free>
+{
+ protected:
+ typedef boost::pool<boost::default_user_allocator_malloc_free> Base;
+ typedef T* pointer;
+ Base& base(){return *this;}
+ Base const& base()const{return *this;}
+ public:
+ typedef T element_type;
+ typedef boost::default_user_allocator_malloc_free user_allocator;
+ typedef typename Base::size_type size_type;
+ typedef typename Base::difference_type difference_type;
+ template<class...U>
+ Simple_object_pool(U&&...u) : Base(sizeof(T), std::forward<U>(u)...) {}
+ template<class...U>
+ pointer construct(U&&...u){
+ void* p=base().malloc BOOST_PREVENT_MACRO_SUBSTITUTION();
+ assert(p);
+ try { new(p) T(std::forward<U>(u)...); }
+ catch(...) {
+ base().free BOOST_PREVENT_MACRO_SUBSTITUTION(p);
+ throw;
+ }
+ return static_cast<pointer>(p);
+ }
+ void destroy(pointer p){
+ p->~T();
+ base().free BOOST_PREVENT_MACRO_SUBSTITUTION(p);
+ }
+};
+}