1 //////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
4 // Software License, Version 1.0. (See accompanying file
5 // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // See http://www.boost.org/libs/container for documentation.
9 //////////////////////////////////////////////////////////////////////////////
11 #ifndef BOOST_CONTAINER_DETAIL_POOL_COMMON_ALLOC_HPP
12 #define BOOST_CONTAINER_DETAIL_POOL_COMMON_ALLOC_HPP
14 #ifndef BOOST_CONFIG_HPP
15 # include <boost/config.hpp>
18 #if defined(BOOST_HAS_PRAGMA_ONCE)
22 #include <boost/container/detail/config_begin.hpp>
23 #include <boost/container/detail/workaround.hpp>
24 #include <boost/container/throw_exception.hpp>
26 #include <boost/intrusive/slist.hpp>
27 #include <boost/container/detail/pool_common.hpp>
28 #include <boost/container/detail/dlmalloc.hpp>
33 namespace container_detail{
35 struct node_slist_helper
36 : public boost::container::container_detail::node_slist<void*>
39 struct fake_segment_manager
41 typedef void * void_pointer;
42 static const std::size_t PayloadPerAllocation = BOOST_CONTAINER_ALLOCATION_PAYLOAD;
44 typedef boost::container::container_detail::
45 basic_multiallocation_chain<void*> multiallocation_chain;
46 static void deallocate(void_pointer p)
49 static void deallocate_many(multiallocation_chain &chain)
51 std::size_t size = chain.size();
52 std::pair<void*, void*> ptrs = chain.extract_data();
53 dlmalloc_memchain dlchain;
54 BOOST_CONTAINER_MEMCHAIN_INIT_FROM(&dlchain, ptrs.first, ptrs.second, size);
55 dlmalloc_multidealloc(&dlchain);
58 typedef std::ptrdiff_t difference_type;
59 typedef std::size_t size_type;
61 static void *allocate_aligned(std::size_t nbytes, std::size_t alignment)
63 void *ret = dlmalloc_memalign(nbytes, alignment);
65 boost::container::throw_bad_alloc();
69 static void *allocate(std::size_t nbytes)
71 void *ret = dlmalloc_malloc(nbytes);
73 boost::container::throw_bad_alloc();
79 } //namespace container{
80 } //namespace container_detail{
84 namespace container_detail {
87 struct is_stateless_segment_manager;
90 struct is_stateless_segment_manager
91 <boost::container::container_detail::fake_segment_manager>
93 static const bool value = true;
96 } //namespace container_detail {
97 } //namespace container {
100 #include <boost/container/detail/config_end.hpp>
102 #endif //BOOST_CONTAINER_DETAIL_POOL_COMMON_ALLOC_HPP