File indexing completed on 2025-01-18 09:30:13
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_CONTAINER_DETAIL_POOL_COMMON_ALLOC_HPP
0012 #define BOOST_CONTAINER_DETAIL_POOL_COMMON_ALLOC_HPP
0013
0014 #ifndef BOOST_CONFIG_HPP
0015 # include <boost/config.hpp>
0016 #endif
0017
0018 #if defined(BOOST_HAS_PRAGMA_ONCE)
0019 # pragma once
0020 #endif
0021
0022 #include <boost/container/detail/config_begin.hpp>
0023 #include <boost/container/detail/workaround.hpp>
0024 #include <boost/container/throw_exception.hpp>
0025
0026 #include <boost/intrusive/slist.hpp>
0027 #include <boost/container/detail/pool_common.hpp>
0028 #include <boost/container/detail/dlmalloc.hpp>
0029 #include <cstddef>
0030
0031 namespace boost{
0032 namespace container{
0033 namespace dtl{
0034
0035 struct node_slist_helper
0036 : public boost::container::dtl::node_slist<void*>
0037 {};
0038
0039 struct fake_segment_manager
0040 {
0041 typedef void * void_pointer;
0042 static const std::size_t PayloadPerAllocation = BOOST_CONTAINER_ALLOCATION_PAYLOAD;
0043
0044 typedef boost::container::dtl::
0045 basic_multiallocation_chain<void*> multiallocation_chain;
0046 static void deallocate(void_pointer p)
0047 { dlmalloc_free(p); }
0048
0049 static void deallocate_many(multiallocation_chain &chain)
0050 {
0051 std::size_t size = chain.size();
0052 multiallocation_chain::pointer_pair ptrs = chain.extract_data();
0053 dlmalloc_memchain dlchain;
0054 BOOST_CONTAINER_MEMCHAIN_INIT_FROM(&dlchain, ptrs.first, ptrs.second, size);
0055 dlmalloc_multidealloc(&dlchain);
0056 }
0057
0058 typedef std::ptrdiff_t difference_type;
0059 typedef std::size_t size_type;
0060
0061 static void *allocate_aligned(std::size_t nbytes, std::size_t alignment)
0062 {
0063 void *ret = dlmalloc_memalign(nbytes, alignment);
0064 if(!ret)
0065 boost::container::throw_bad_alloc();
0066 return ret;
0067 }
0068
0069 static void *allocate(std::size_t nbytes)
0070 {
0071 void *ret = dlmalloc_malloc(nbytes);
0072 if(!ret)
0073 boost::container::throw_bad_alloc();
0074 return ret;
0075 }
0076 };
0077
0078 }
0079 }
0080 }
0081
0082 namespace boost {
0083 namespace container {
0084 namespace dtl {
0085
0086 template<class T>
0087 struct is_stateless_segment_manager;
0088
0089 template<>
0090 struct is_stateless_segment_manager
0091 <boost::container::dtl::fake_segment_manager>
0092 {
0093 static const bool value = true;
0094 };
0095
0096 }
0097 }
0098 }
0099
0100 #include <boost/container/detail/config_end.hpp>
0101
0102 #endif