38 #ifndef NEKTAR_LIB_UTILITIES_NEK_MEMORY_MANAGER_H
39 #define NEKTAR_LIB_UTILITIES_NEK_MEMORY_MANAGER_H
45 #include <boost/mpl/contains.hpp>
46 #include <boost/mpl/list_c.hpp>
47 #include <boost/shared_ptr.hpp>
48 #include <boost/utility/enable_if.hpp>
49 #include <boost/mpl/integral_c.hpp>
50 #include <boost/bind.hpp>
51 #include <boost/type_traits.hpp>
53 #include <boost/preprocessor/repetition/enum_params.hpp>
54 #include <boost/preprocessor/repetition/repeat_from_to.hpp>
55 #include <boost/preprocessor/repetition/enum_trailing.hpp>
56 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
57 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
58 #include <boost/preprocessor/control/if.hpp>
59 #include <boost/preprocessor/facilities/empty.hpp>
60 #include <boost/preprocessor/comparison/equal.hpp>
61 #include <boost/preprocessor/punctuation/comma.hpp>
62 #include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
73 #ifndef NEKTAR_MAX_MEMORY_MANAGER_CONSTRUCTOR_ARGS
74 #define NEKTAR_MAX_MEMORY_MANAGER_CONSTRUCTOR_ARGS 15
75 #endif //NEKTAR_MAX_MEMORY_MANAGER_CONSTRUCTOR_ARGS
101 template<
typename DataType>
105 template<
typename ObjectType,
typename CustomDeallocator>
149 #ifdef NEKTAR_MEMORY_POOL_ENABLED
152 #else //NEKTAR_MEMORY_POOL_ENABLED
154 #endif //NEKTAR_MEMORY_POOL_ENABLED
159 #ifdef NEKTAR_MEMORY_POOL_ENABLED
175 new (result) DataType();
187 #define ALLOCATE_METHOD_GENERATOR(z, i, methodName) \
188 template<BOOST_PP_ENUM_PARAMS(i, typename Arg)> \
189 static DataType* methodName(BOOST_PP_ENUM_BINARY_PARAMS(i, const Arg, & arg)) \
191 DataType* result = static_cast<DataType*>(GetMemoryPool().Allocate(sizeof(DataType))); \
197 new (result) DataType(BOOST_PP_ENUM_PARAMS(i, arg)); \
201 GetMemoryPool().Deallocate(result, sizeof(DataType)); \
208 #else //NEKTAR_MEMORY_POOL_ENABLED
217 return new DataType();
220 #define ALLOCATE_METHOD_GENERATOR(z, i, methodName) \
221 template<BOOST_PP_ENUM_PARAMS(i, typename Arg)> \
222 static DataType* methodName(BOOST_PP_ENUM_BINARY_PARAMS(i, const Arg, & arg)) \
224 return new DataType(BOOST_PP_ENUM_PARAMS(i, arg)); \
226 #endif //NEKTAR_MEMORY_POOL_ENABLED
264 #define ALLOCATE_SHARED_PTR_METHOD_GENERATOR(z, i, methodName) \
265 template<BOOST_PP_ENUM_PARAMS(i, typename Arg)> \
266 static boost::shared_ptr<DataType> methodName(BOOST_PP_ENUM_BINARY_PARAMS(i, const Arg, & arg)) \
268 return AllocateSharedPtrD(DefaultCustomDeallocator(), BOOST_PP_ENUM_PARAMS(i, arg)); \
271 #define ALLOCATE_SHARED_PTR_METHOD_WITH_DEALLOCATOR_GENERATOR(z, i, methodName) \
272 template<typename DeallocatorType BOOST_PP_ENUM_TRAILING_PARAMS(i, typename Arg)> \
273 static boost::shared_ptr<DataType> methodName(const DeallocatorType& d BOOST_PP_ENUM_TRAILING_BINARY_PARAMS(i, Arg, & arg)) \
275 DataType* data = Allocate(BOOST_PP_ENUM_PARAMS(i, arg)); \
276 return boost::shared_ptr<DataType>(data, DeallocateSharedPtr<DataType, DeallocatorType>(d)); \
292 #ifdef NEKTAR_MEMORY_POOL_ENABLED
294 #else //NEKTAR_MEMORY_POOL_ENABLED
295 return static_cast<DataType*
>(::operator
new(NumberOfElements *
sizeof(DataType)));
296 #endif //NEKTAR_MEMORY_POOL_ENABLED
308 #ifdef NEKTAR_MEMORY_POOL_ENABLED
310 #else //NEKTAR_MEMORY_POOL_ENABLED
311 ::operator
delete(array);
312 #endif //NEKTAR_MEMORY_POOL_ENABLED
350 new(p) DataType(val);
360 return std::numeric_limits<size_type>::max()/
sizeof(DataType);
377 template<
typename DataType>
383 template<
typename DataType>
386 return !(lhs == rhs);
391 #endif //NEKTAR_LIB_UTILITIES_NEK_MEMORY_MANAGER_H