Made allocator switchable at compile time in Fast*
parent
f6fc000e12
commit
e3ea39f182
|
|
@ -0,0 +1,64 @@
|
|||
/* ----------------------------------------------------------------------------
|
||||
|
||||
* 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 FastDefaultAllocator.h
|
||||
* @brief An easy way to control which allocator is used for Fast* collections
|
||||
* @author Richard Roberts
|
||||
* @date Aug 15, 2013
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined GTSAM_ALLOCATOR_BOOSTPOOL && !defined GTSAM_ALLOCATOR_TBB && !defined GTSAM_ALLOCATOR_STL
|
||||
// Use TBB allocator by default
|
||||
# define GTSAM_ALLOCATOR_TBB
|
||||
#endif
|
||||
|
||||
#if defined GTSAM_ALLOCATOR_BOOSTPOOL
|
||||
# include <boost/pool/pool_alloc.hpp>
|
||||
#elif defined GTSAM_ALLOCATOR_TBB
|
||||
# include <tbb/tbb_allocator.h>
|
||||
# undef min
|
||||
# undef max
|
||||
# undef ERROR
|
||||
#elif defined GTSAM_ALLOCATOR_STL
|
||||
# include <memory>
|
||||
#endif
|
||||
|
||||
namespace gtsam
|
||||
{
|
||||
|
||||
namespace internal
|
||||
{
|
||||
template<typename T>
|
||||
struct FastDefaultAllocator
|
||||
{
|
||||
#if defined GTSAM_ALLOCATOR_BOOSTPOOL
|
||||
typedef boost::fast_pool_allocator<T> type;
|
||||
static const bool isBoost = true;
|
||||
static const bool isTBB = false;
|
||||
static const bool isSTL = false;
|
||||
#elif defined GTSAM_ALLOCATOR_TBB
|
||||
typedef tbb::tbb_allocator<T> type;
|
||||
static const bool isBoost = false;
|
||||
static const bool isTBB = true;
|
||||
static const bool isSTL = false;
|
||||
#elif defined GTSAM_ALLOCATOR_STL
|
||||
typedef std::allocator<T> type;
|
||||
static const bool isBoost = false;
|
||||
static const bool isTBB = false;
|
||||
static const bool isSTL = true;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,8 +18,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <gtsam/base/FastDefaultAllocator.h>
|
||||
#include <list>
|
||||
#include <boost/pool/pool_alloc.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/list.hpp>
|
||||
|
||||
|
|
@ -34,11 +35,11 @@ namespace gtsam {
|
|||
* @addtogroup base
|
||||
*/
|
||||
template<typename VALUE>
|
||||
class FastList: public std::list<VALUE, boost::fast_pool_allocator<VALUE> > {
|
||||
class FastList: public std::list<VALUE, typename internal::FastDefaultAllocator<VALUE>::type> {
|
||||
|
||||
public:
|
||||
|
||||
typedef std::list<VALUE, boost::fast_pool_allocator<VALUE> > Base;
|
||||
typedef std::list<VALUE, typename internal::FastDefaultAllocator<VALUE>::type> Base;
|
||||
|
||||
/** Default constructor */
|
||||
FastList() {}
|
||||
|
|
@ -54,7 +55,7 @@ public:
|
|||
FastList(const Base& x) : Base(x) {}
|
||||
|
||||
/** Copy constructor from a standard STL container */
|
||||
FastList(const std::list<VALUE>& x) {
|
||||
FastList(const std::list<VALUE>& x, typename boost::disable_if_c<internal::FastDefaultAllocator<VALUE>::isSTL>::type* = 0) {
|
||||
// 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.
|
||||
|
|
|
|||
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <gtsam/base/FastDefaultAllocator.h>
|
||||
#include <map>
|
||||
#include <boost/pool/pool_alloc.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/map.hpp>
|
||||
|
||||
|
|
@ -34,11 +34,13 @@ namespace gtsam {
|
|||
* @addtogroup base
|
||||
*/
|
||||
template<typename KEY, typename VALUE>
|
||||
class FastMap : public std::map<KEY, VALUE, std::less<KEY>, boost::fast_pool_allocator<std::pair<const KEY, VALUE> > > {
|
||||
class FastMap : public std::map<KEY, VALUE, std::less<KEY>,
|
||||
typename internal::FastDefaultAllocator<std::pair<const KEY, VALUE> >::type> {
|
||||
|
||||
public:
|
||||
|
||||
typedef std::map<KEY, VALUE, std::less<KEY>, boost::fast_pool_allocator<std::pair<const KEY, VALUE> > > Base;
|
||||
typedef std::map<KEY, VALUE, std::less<KEY>,
|
||||
typename internal::FastDefaultAllocator<std::pair<const KEY, VALUE> >::type > Base;
|
||||
|
||||
/** Default constructor */
|
||||
FastMap() {}
|
||||
|
|
|
|||
|
|
@ -18,11 +18,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <gtsam/base/FastDefaultAllocator.h>
|
||||
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
#include <boost/pool/pool_alloc.hpp>
|
||||
#include <boost/mpl/has_xxx.hpp>
|
||||
#include <boost/utility/enable_if.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
|
|
@ -45,11 +46,11 @@ struct FastSetTestableHelper;
|
|||
* @addtogroup base
|
||||
*/
|
||||
template<typename VALUE, class ENABLE = void>
|
||||
class FastSet: public std::set<VALUE, std::less<VALUE>, boost::fast_pool_allocator<VALUE> > {
|
||||
class FastSet: public std::set<VALUE, std::less<VALUE>, typename internal::FastDefaultAllocator<VALUE>::type> {
|
||||
|
||||
public:
|
||||
|
||||
typedef std::set<VALUE, std::less<VALUE>, boost::fast_pool_allocator<VALUE> > Base;
|
||||
typedef std::set<VALUE, std::less<VALUE>, typename internal::FastDefaultAllocator<VALUE>::type> Base;
|
||||
|
||||
/** Default constructor */
|
||||
FastSet() {
|
||||
|
|
@ -78,7 +79,7 @@ public:
|
|||
}
|
||||
|
||||
/** Copy constructor from a standard STL container */
|
||||
FastSet(const std::set<VALUE>& x) {
|
||||
FastSet(const std::set<VALUE>& x, typename boost::disable_if_c<internal::FastDefaultAllocator<VALUE>::isSTL>::type* = 0) {
|
||||
// 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.
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
#include <boost/pool/pool_alloc.hpp>
|
||||
#include <boost/serialization/nvp.hpp>
|
||||
#include <boost/serialization/vector.hpp>
|
||||
|
||||
|
|
@ -36,11 +35,11 @@ namespace gtsam {
|
|||
* @addtogroup base
|
||||
*/
|
||||
template<typename VALUE>
|
||||
class FastVector: public std::vector<VALUE, boost::pool_allocator<VALUE> > {
|
||||
class FastVector: public std::vector<VALUE, typename internal::FastDefaultAllocator<VALUE>::type> {
|
||||
|
||||
public:
|
||||
|
||||
typedef std::vector<VALUE, boost::pool_allocator<VALUE> > Base;
|
||||
typedef std::vector<VALUE, typename internal::FastDefaultAllocator<VALUE>::type> Base;
|
||||
|
||||
/** Default constructor */
|
||||
FastVector() {}
|
||||
|
|
@ -80,7 +79,7 @@ public:
|
|||
FastVector(const Base& x) : Base(x) {}
|
||||
|
||||
/** Copy constructor from a standard STL container */
|
||||
FastVector(const std::vector<VALUE>& x) {
|
||||
FastVector(const std::vector<VALUE>& x, typename boost::disable_if_c<internal::FastDefaultAllocator<VALUE>::isSTL>::type* = 0) {
|
||||
// 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.
|
||||
|
|
|
|||
Loading…
Reference in New Issue