?????????? ????????? - ??????????????? - /home/agenciai/public_html/cd38d8/adaptive_pool.hpp.tar
???????
usr/include/boost/interprocess/allocators/adaptive_pool.hpp 0000644 00000043062 15127146550 0020363 0 ustar 00 ////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2005-2012. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/interprocess for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_INTERPROCESS_ADAPTIVE_POOL_HPP #define BOOST_INTERPROCESS_ADAPTIVE_POOL_HPP #ifndef BOOST_CONFIG_HPP # include <boost/config.hpp> #endif # #if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once #endif #include <boost/interprocess/detail/config_begin.hpp> #include <boost/interprocess/detail/workaround.hpp> #include <boost/intrusive/pointer_traits.hpp> #include <boost/interprocess/interprocess_fwd.hpp> #include <boost/assert.hpp> #include <boost/utility/addressof.hpp> #include <boost/interprocess/detail/utilities.hpp> #include <boost/interprocess/detail/type_traits.hpp> #include <boost/interprocess/allocators/detail/adaptive_node_pool.hpp> #include <boost/interprocess/containers/version_type.hpp> #include <boost/interprocess/exceptions.hpp> #include <boost/interprocess/allocators/detail/allocator_common.hpp> #include <boost/container/detail/multiallocation_chain.hpp> #include <boost/interprocess/detail/mpl.hpp> #include <boost/move/adl_move_swap.hpp> #include <cstddef> //!\file //!Describes adaptive_pool pooled shared memory STL compatible allocator namespace boost { namespace interprocess { #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) namespace ipcdetail{ template < unsigned int Version , class T , class SegmentManager , std::size_t NodesPerBlock , std::size_t MaxFreeBlocks , unsigned char OverheadPercent > class adaptive_pool_base : public node_pool_allocation_impl < adaptive_pool_base < Version, T, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> , Version , T , SegmentManager > { public: typedef typename SegmentManager::void_pointer void_pointer; typedef SegmentManager segment_manager; typedef adaptive_pool_base <Version, T, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> self_t; #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) template <int dummy> struct node_pool { typedef ipcdetail::shared_adaptive_node_pool < SegmentManager, sizeof_value<T>::value, NodesPerBlock, MaxFreeBlocks, OverheadPercent> type; static type *get(void *p) { return static_cast<type*>(p); } }; #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED BOOST_STATIC_ASSERT((Version <=2)); public: //------- typedef typename boost::intrusive:: pointer_traits<void_pointer>::template rebind_pointer<T>::type pointer; typedef typename boost::intrusive:: pointer_traits<void_pointer>::template rebind_pointer<const T>::type const_pointer; typedef T value_type; typedef typename ipcdetail::add_reference <value_type>::type reference; typedef typename ipcdetail::add_reference <const value_type>::type const_reference; typedef typename segment_manager::size_type size_type; typedef typename segment_manager::difference_type difference_type; typedef boost::interprocess::version_type<adaptive_pool_base, Version> version; typedef boost::container::dtl::transform_multiallocation_chain <typename SegmentManager::multiallocation_chain, T>multiallocation_chain; //!Obtains adaptive_pool_base from //!adaptive_pool_base template<class T2> struct rebind { typedef adaptive_pool_base<Version, T2, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> other; }; #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) private: //!Not assignable from related adaptive_pool_base template<unsigned int Version2, class T2, class SegmentManager2, std::size_t N2, std::size_t F2, unsigned char O2> adaptive_pool_base& operator= (const adaptive_pool_base<Version2, T2, SegmentManager2, N2, F2, O2>&); #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED public: //!Constructor from a segment manager. If not present, constructs a node //!pool. Increments the reference count of the associated node pool. //!Can throw boost::interprocess::bad_alloc adaptive_pool_base(segment_manager *segment_mngr) : mp_node_pool(ipcdetail::get_or_create_node_pool<typename node_pool<0>::type>(segment_mngr)) { } //!Copy constructor from other adaptive_pool_base. Increments the reference //!count of the associated node pool. Never throws adaptive_pool_base(const adaptive_pool_base &other) : mp_node_pool(other.get_node_pool()) { node_pool<0>::get(ipcdetail::to_raw_pointer(mp_node_pool))->inc_ref_count(); } //!Assignment from other adaptive_pool_base adaptive_pool_base& operator=(const adaptive_pool_base &other) { adaptive_pool_base c(other); boost::adl_move_swap(*this, c); return *this; } //!Copy constructor from related adaptive_pool_base. If not present, constructs //!a node pool. Increments the reference count of the associated node pool. //!Can throw boost::interprocess::bad_alloc template<class T2> adaptive_pool_base (const adaptive_pool_base<Version, T2, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> &other) : mp_node_pool(ipcdetail::get_or_create_node_pool<typename node_pool<0>::type>(other.get_segment_manager())) { } //!Destructor, removes node_pool_t from memory //!if its reference count reaches to zero. Never throws ~adaptive_pool_base() { ipcdetail::destroy_node_pool_if_last_link(node_pool<0>::get(ipcdetail::to_raw_pointer(mp_node_pool))); } //!Returns a pointer to the node pool. //!Never throws void* get_node_pool() const { return ipcdetail::to_raw_pointer(mp_node_pool); } //!Returns the segment manager. //!Never throws segment_manager* get_segment_manager()const { return node_pool<0>::get(ipcdetail::to_raw_pointer(mp_node_pool))->get_segment_manager(); } //!Swaps allocators. Does not throw. If each allocator is placed in a //!different memory segment, the result is undefined. friend void swap(self_t &alloc1, self_t &alloc2) { boost::adl_move_swap(alloc1.mp_node_pool, alloc2.mp_node_pool); } #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) private: void_pointer mp_node_pool; #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED }; //!Equality test for same type //!of adaptive_pool_base template<unsigned int V, class T, class S, std::size_t NPC, std::size_t F, unsigned char OP> inline bool operator==(const adaptive_pool_base<V, T, S, NPC, F, OP> &alloc1, const adaptive_pool_base<V, T, S, NPC, F, OP> &alloc2) { return alloc1.get_node_pool() == alloc2.get_node_pool(); } //!Inequality test for same type //!of adaptive_pool_base template<unsigned int V, class T, class S, std::size_t NPC, std::size_t F, unsigned char OP> inline bool operator!=(const adaptive_pool_base<V, T, S, NPC, F, OP> &alloc1, const adaptive_pool_base<V, T, S, NPC, F, OP> &alloc2) { return alloc1.get_node_pool() != alloc2.get_node_pool(); } template < class T , class SegmentManager , std::size_t NodesPerBlock = 64 , std::size_t MaxFreeBlocks = 2 , unsigned char OverheadPercent = 5 > class adaptive_pool_v1 : public adaptive_pool_base < 1 , T , SegmentManager , NodesPerBlock , MaxFreeBlocks , OverheadPercent > { public: typedef ipcdetail::adaptive_pool_base < 1, T, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> base_t; template<class T2> struct rebind { typedef adaptive_pool_v1<T2, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> other; }; adaptive_pool_v1(SegmentManager *segment_mngr) : base_t(segment_mngr) {} template<class T2> adaptive_pool_v1 (const adaptive_pool_v1<T2, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> &other) : base_t(other) {} }; } //namespace ipcdetail{ #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED //!An STL node allocator that uses a segment manager as memory //!source. The internal pointer type will of the same type (raw, smart) as //!"typename SegmentManager::void_pointer" type. This allows //!placing the allocator in shared memory, memory mapped-files, etc... //! //!This node allocator shares a segregated storage between all instances //!of adaptive_pool with equal sizeof(T) placed in the same segment //!group. NodesPerBlock is the number of nodes allocated at once when the allocator //!needs runs out of nodes. MaxFreeBlocks is the maximum number of totally free blocks //!that the adaptive node pool will hold. The rest of the totally free blocks will be //!deallocated with the segment manager. //! //!OverheadPercent is the (approximated) maximum size overhead (1-20%) of the allocator: //!(memory usable for nodes / total memory allocated from the segment manager) template < class T , class SegmentManager , std::size_t NodesPerBlock , std::size_t MaxFreeBlocks , unsigned char OverheadPercent > class adaptive_pool #if !defined(BOOST_INTERPROCESS_DOXYGEN_INVOKED) : public ipcdetail::adaptive_pool_base < 2 , T , SegmentManager , NodesPerBlock , MaxFreeBlocks , OverheadPercent > #endif //#ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED { #ifndef BOOST_INTERPROCESS_DOXYGEN_INVOKED typedef ipcdetail::adaptive_pool_base < 2, T, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> base_t; public: typedef boost::interprocess::version_type<adaptive_pool, 2> version; template<class T2> struct rebind { typedef adaptive_pool<T2, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> other; }; adaptive_pool(SegmentManager *segment_mngr) : base_t(segment_mngr) {} template<class T2> adaptive_pool (const adaptive_pool<T2, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> &other) : base_t(other) {} #else //BOOST_INTERPROCESS_DOXYGEN_INVOKED public: typedef implementation_defined::segment_manager segment_manager; typedef segment_manager::void_pointer void_pointer; typedef implementation_defined::pointer pointer; typedef implementation_defined::const_pointer const_pointer; typedef T value_type; typedef typename ipcdetail::add_reference <value_type>::type reference; typedef typename ipcdetail::add_reference <const value_type>::type const_reference; typedef typename segment_manager::size_type size_type; typedef typename segment_manager::difference_type difference_type; //!Obtains adaptive_pool from //!adaptive_pool template<class T2> struct rebind { typedef adaptive_pool<T2, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> other; }; private: //!Not assignable from //!related adaptive_pool template<class T2, class SegmentManager2, std::size_t N2, std::size_t F2, unsigned char OP2> adaptive_pool& operator= (const adaptive_pool<T2, SegmentManager2, N2, F2, OP2>&); //!Not assignable from //!other adaptive_pool //adaptive_pool& operator=(const adaptive_pool&); public: //!Constructor from a segment manager. If not present, constructs a node //!pool. Increments the reference count of the associated node pool. //!Can throw boost::interprocess::bad_alloc adaptive_pool(segment_manager *segment_mngr); //!Copy constructor from other adaptive_pool. Increments the reference //!count of the associated node pool. Never throws adaptive_pool(const adaptive_pool &other); //!Copy constructor from related adaptive_pool. If not present, constructs //!a node pool. Increments the reference count of the associated node pool. //!Can throw boost::interprocess::bad_alloc template<class T2> adaptive_pool (const adaptive_pool<T2, SegmentManager, NodesPerBlock, MaxFreeBlocks, OverheadPercent> &other); //!Destructor, removes node_pool_t from memory //!if its reference count reaches to zero. Never throws ~adaptive_pool(); //!Returns a pointer to the node pool. //!Never throws void* get_node_pool() const; //!Returns the segment manager. //!Never throws segment_manager* get_segment_manager()const; //!Returns the number of elements that could be allocated. //!Never throws size_type max_size() const; //!Allocate memory for an array of count elements. //!Throws boost::interprocess::bad_alloc if there is no enough memory pointer allocate(size_type count, cvoid_pointer hint = 0); //!Deallocate allocated memory. //!Never throws void deallocate(const pointer &ptr, size_type count); //!Deallocates all free blocks //!of the pool void deallocate_free_blocks(); //!Swaps allocators. Does not throw. If each allocator is placed in a //!different memory segment, the result is undefined. friend void swap(self_t &alloc1, self_t &alloc2); //!Returns address of mutable object. //!Never throws pointer address(reference value) const; //!Returns address of non mutable object. //!Never throws const_pointer address(const_reference value) const; /* //!Copy construct an object. //!Throws if T's copy constructor throws void construct(const pointer &ptr, const_reference v); //!Destroys object. Throws if object's //!destructor throws void destroy(const pointer &ptr); */ //!Returns maximum the number of objects the previously allocated memory //!pointed by p can hold. This size only works for memory allocated with //!allocate, allocation_command and allocate_many. size_type size(const pointer &p) const; pointer allocation_command(boost::interprocess::allocation_type command, size_type limit_size, size_type &prefer_in_recvd_out_size, pointer &reuse); //!Allocates many elements of size elem_size in a contiguous block //!of memory. The minimum number to be allocated is min_elements, //!the preferred and maximum number is //!preferred_elements. The number of actually allocated elements is //!will be assigned to received_size. The elements must be deallocated //!with deallocate(...) void allocate_many(size_type elem_size, size_type num_elements, multiallocation_chain &chain); //!Allocates n_elements elements, each one of size elem_sizes[i]in a //!contiguous block //!of memory. The elements must be deallocated void allocate_many(const size_type *elem_sizes, size_type n_elements, multiallocation_chain &chain); //!Allocates many elements of size elem_size in a contiguous block //!of memory. The minimum number to be allocated is min_elements, //!the preferred and maximum number is //!preferred_elements. The number of actually allocated elements is //!will be assigned to received_size. The elements must be deallocated //!with deallocate(...) void deallocate_many(multiallocation_chain &chain); //!Allocates just one object. Memory allocated with this function //!must be deallocated only with deallocate_one(). //!Throws boost::interprocess::bad_alloc if there is no enough memory pointer allocate_one(); //!Allocates many elements of size == 1 in a contiguous block //!of memory. The minimum number to be allocated is min_elements, //!the preferred and maximum number is //!preferred_elements. The number of actually allocated elements is //!will be assigned to received_size. Memory allocated with this function //!must be deallocated only with deallocate_one(). void allocate_individual(size_type num_elements, multiallocation_chain &chain); //!Deallocates memory previously allocated with allocate_one(). //!You should never use deallocate_one to deallocate memory allocated //!with other functions different from allocate_one(). Never throws void deallocate_one(const pointer &p); //!Allocates many elements of size == 1 in a contiguous block //!of memory. The minimum number to be allocated is min_elements, //!the preferred and maximum number is //!preferred_elements. The number of actually allocated elements is //!will be assigned to received_size. Memory allocated with this function //!must be deallocated only with deallocate_one(). void deallocate_individual(multiallocation_chain &chain); #endif }; #ifdef BOOST_INTERPROCESS_DOXYGEN_INVOKED //!Equality test for same type //!of adaptive_pool template<class T, class S, std::size_t NodesPerBlock, std::size_t F, unsigned char OP> inline bool operator==(const adaptive_pool<T, S, NodesPerBlock, F, OP> &alloc1, const adaptive_pool<T, S, NodesPerBlock, F, OP> &alloc2); //!Inequality test for same type //!of adaptive_pool template<class T, class S, std::size_t NodesPerBlock, std::size_t F, unsigned char OP> inline bool operator!=(const adaptive_pool<T, S, NodesPerBlock, F, OP> &alloc1, const adaptive_pool<T, S, NodesPerBlock, F, OP> &alloc2); #endif } //namespace interprocess { } //namespace boost { #include <boost/interprocess/detail/config_end.hpp> #endif //#ifndef BOOST_INTERPROCESS_ADAPTIVE_POOL_HPP usr/include/boost/container/adaptive_pool.hpp 0000644 00000056145 15127532764 0015476 0 ustar 00 ////////////////////////////////////////////////////////////////////////////// // // (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost // Software License, Version 1.0. (See accompanying file // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) // // See http://www.boost.org/libs/container for documentation. // ////////////////////////////////////////////////////////////////////////////// #ifndef BOOST_CONTAINER_ADAPTIVE_POOL_HPP #define BOOST_CONTAINER_ADAPTIVE_POOL_HPP #ifndef BOOST_CONFIG_HPP # include <boost/config.hpp> #endif #if defined(BOOST_HAS_PRAGMA_ONCE) # pragma once #endif #include <boost/container/detail/config_begin.hpp> #include <boost/container/detail/workaround.hpp> #include <boost/container/container_fwd.hpp> #include <boost/container/detail/version_type.hpp> #include <boost/container/throw_exception.hpp> #include <boost/container/detail/adaptive_node_pool.hpp> #include <boost/container/detail/multiallocation_chain.hpp> #include <boost/container/detail/mpl.hpp> #include <boost/container/detail/dlmalloc.hpp> #include <boost/container/detail/singleton.hpp> #include <boost/container/detail/placement_new.hpp> #include <boost/assert.hpp> #include <boost/static_assert.hpp> #include <boost/move/utility_core.hpp> #include <cstddef> namespace boost { namespace container { //!An STL node allocator that uses a modified DLMalloc as memory //!source. //! //!This node allocator shares a segregated storage between all instances //!of adaptive_pool with equal sizeof(T). //! //!NodesPerBlock is the number of nodes allocated at once when the allocator //!needs runs out of nodes. MaxFreeBlocks is the maximum number of totally free blocks //!that the adaptive node pool will hold. The rest of the totally free blocks will be //!deallocated to the memory manager. //! //!OverheadPercent is the (approximated) maximum size overhead (1-20%) of the allocator: //!(memory usable for nodes / total memory allocated from the memory allocator) template < class T , std::size_t NodesPerBlock BOOST_CONTAINER_DOCONLY(= ADP_nodes_per_block) , std::size_t MaxFreeBlocks BOOST_CONTAINER_DOCONLY(= ADP_max_free_blocks) , std::size_t OverheadPercent BOOST_CONTAINER_DOCONLY(= ADP_overhead_percent) BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I unsigned Version) > class adaptive_pool { //!If Version is 1, the allocator is a STL conforming allocator. If Version is 2, //!the allocator offers advanced expand in place and burst allocation capabilities. public: typedef unsigned int allocation_type; typedef adaptive_pool <T, NodesPerBlock, MaxFreeBlocks, OverheadPercent BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I Version) > self_t; static const std::size_t nodes_per_block = NodesPerBlock; static const std::size_t max_free_blocks = MaxFreeBlocks; static const std::size_t overhead_percent = OverheadPercent; static const std::size_t real_nodes_per_block = NodesPerBlock; BOOST_CONTAINER_DOCIGN(BOOST_STATIC_ASSERT((Version <=2))); public: //------- typedef T value_type; typedef T * pointer; typedef const T * const_pointer; typedef typename ::boost::container:: dtl::unvoid_ref<T>::type reference; typedef typename ::boost::container:: dtl::unvoid_ref<const T>::type const_reference; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; typedef boost::container::dtl:: version_type<self_t, Version> version; #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED typedef boost::container::dtl:: basic_multiallocation_chain<void*> multiallocation_chain_void; typedef boost::container::dtl:: transform_multiallocation_chain <multiallocation_chain_void, T> multiallocation_chain; #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED //!Obtains adaptive_pool from //!adaptive_pool template<class T2> struct rebind { typedef adaptive_pool < T2 , NodesPerBlock , MaxFreeBlocks , OverheadPercent BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I Version) > other; }; #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED private: //!Not assignable from related adaptive_pool template<class T2, std::size_t N2, std::size_t F2, std::size_t O2, unsigned Version2> adaptive_pool& operator= (const adaptive_pool<T2, N2, F2, O2, Version2>&); #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED public: //!Default constructor adaptive_pool() BOOST_NOEXCEPT_OR_NOTHROW {} //!Copy constructor from other adaptive_pool. adaptive_pool(const adaptive_pool &) BOOST_NOEXCEPT_OR_NOTHROW {} //!Copy assignment from other adaptive_pool. adaptive_pool & operator=(const adaptive_pool &) BOOST_NOEXCEPT_OR_NOTHROW { return *this; } //!Copy constructor from related adaptive_pool. template<class T2> adaptive_pool (const adaptive_pool<T2, NodesPerBlock, MaxFreeBlocks, OverheadPercent BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I Version)> &) BOOST_NOEXCEPT_OR_NOTHROW {} //!Destructor ~adaptive_pool() BOOST_NOEXCEPT_OR_NOTHROW {} //!Returns the number of elements that could be allocated. //!Never throws size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW { return size_type(-1)/(2u*sizeof(T)); } //!Allocate memory for an array of count elements. //!Throws std::bad_alloc if there is no enough memory pointer allocate(size_type count, const void * = 0) { if(BOOST_UNLIKELY(count > size_type(-1)/(2u*sizeof(T)))) boost::container::throw_bad_alloc(); if(Version == 1 && count == 1){ typedef typename dtl::shared_adaptive_node_pool <sizeof(T), NodesPerBlock, MaxFreeBlocks, OverheadPercent> shared_pool_t; typedef dtl::singleton_default<shared_pool_t> singleton_t; return pointer(static_cast<T*>(singleton_t::instance().allocate_node())); } else{ return static_cast<pointer>(dlmalloc_malloc(count*sizeof(T))); } } //!Deallocate allocated memory. //!Never throws void deallocate(const pointer &ptr, size_type count) BOOST_NOEXCEPT_OR_NOTHROW { (void)count; if(Version == 1 && count == 1){ typedef dtl::shared_adaptive_node_pool <sizeof(T), NodesPerBlock, MaxFreeBlocks, OverheadPercent> shared_pool_t; typedef dtl::singleton_default<shared_pool_t> singleton_t; singleton_t::instance().deallocate_node(ptr); } else{ dlmalloc_free(ptr); } } pointer allocation_command(allocation_type command, size_type limit_size, size_type &prefer_in_recvd_out_size, pointer &reuse) { pointer ret = this->priv_allocation_command(command, limit_size, prefer_in_recvd_out_size, reuse); if(BOOST_UNLIKELY(!ret && !(command & BOOST_CONTAINER_NOTHROW_ALLOCATION))) boost::container::throw_bad_alloc(); return ret; } //!Returns maximum the number of objects the previously allocated memory //!pointed by p can hold. size_type size(pointer p) const BOOST_NOEXCEPT_OR_NOTHROW { return dlmalloc_size(p); } //!Allocates just one object. Memory allocated with this function //!must be deallocated only with deallocate_one(). //!Throws bad_alloc if there is no enough memory pointer allocate_one() { typedef dtl::shared_adaptive_node_pool <sizeof(T), NodesPerBlock, MaxFreeBlocks, OverheadPercent> shared_pool_t; typedef dtl::singleton_default<shared_pool_t> singleton_t; return (pointer)singleton_t::instance().allocate_node(); } //!Allocates many elements of size == 1. //!Elements must be individually deallocated with deallocate_one() void allocate_individual(std::size_t num_elements, multiallocation_chain &chain) { typedef dtl::shared_adaptive_node_pool <sizeof(T), NodesPerBlock, MaxFreeBlocks, OverheadPercent> shared_pool_t; typedef dtl::singleton_default<shared_pool_t> singleton_t; singleton_t::instance().allocate_nodes(num_elements, static_cast<typename shared_pool_t::multiallocation_chain&>(chain)); //typename shared_pool_t::multiallocation_chain ch; //singleton_t::instance().allocate_nodes(num_elements, ch); //chain.incorporate_after //(chain.before_begin(), (T*)&*ch.begin(), (T*)&*ch.last(), ch.size()); } //!Deallocates memory previously allocated with allocate_one(). //!You should never use deallocate_one to deallocate memory allocated //!with other functions different from allocate_one(). Never throws void deallocate_one(pointer p) BOOST_NOEXCEPT_OR_NOTHROW { typedef dtl::shared_adaptive_node_pool <sizeof(T), NodesPerBlock, MaxFreeBlocks, OverheadPercent> shared_pool_t; typedef dtl::singleton_default<shared_pool_t> singleton_t; singleton_t::instance().deallocate_node(p); } void deallocate_individual(multiallocation_chain &chain) BOOST_NOEXCEPT_OR_NOTHROW { typedef dtl::shared_adaptive_node_pool <sizeof(T), NodesPerBlock, MaxFreeBlocks, OverheadPercent> shared_pool_t; typedef dtl::singleton_default<shared_pool_t> singleton_t; //typename shared_pool_t::multiallocation_chain ch(&*chain.begin(), &*chain.last(), chain.size()); //singleton_t::instance().deallocate_nodes(ch); singleton_t::instance().deallocate_nodes(chain); } //!Allocates many elements of size elem_size. //!Elements must be individually deallocated with deallocate() void allocate_many(size_type elem_size, std::size_t n_elements, multiallocation_chain &chain) { BOOST_STATIC_ASSERT(( Version > 1 ));/* dlmalloc_memchain ch; BOOST_CONTAINER_MEMCHAIN_INIT(&ch); if(BOOST_UNLIKELY(!dlmalloc_multialloc_nodes(n_elements, elem_size*sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, &ch))){ boost::container::throw_bad_alloc(); } chain.incorporate_after(chain.before_begin() ,(T*)BOOST_CONTAINER_MEMCHAIN_FIRSTMEM(&ch) ,(T*)BOOST_CONTAINER_MEMCHAIN_LASTMEM(&ch) ,BOOST_CONTAINER_MEMCHAIN_SIZE(&ch) );*/ if(BOOST_UNLIKELY(!dlmalloc_multialloc_nodes (n_elements, elem_size*sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, reinterpret_cast<dlmalloc_memchain *>(&chain)))){ boost::container::throw_bad_alloc(); } } //!Allocates n_elements elements, each one of size elem_sizes[i] //!Elements must be individually deallocated with deallocate() void allocate_many(const size_type *elem_sizes, size_type n_elements, multiallocation_chain &chain) { BOOST_STATIC_ASSERT(( Version > 1 ));/* dlmalloc_memchain ch; BOOST_CONTAINER_MEMCHAIN_INIT(&ch); if(BOOST_UNLIKELY(!dlmalloc_multialloc_arrays(n_elements, elem_sizes, sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, &ch))){ boost::container::throw_bad_alloc(); } chain.incorporate_after(chain.before_begin() ,(T*)BOOST_CONTAINER_MEMCHAIN_FIRSTMEM(&ch) ,(T*)BOOST_CONTAINER_MEMCHAIN_LASTMEM(&ch) ,BOOST_CONTAINER_MEMCHAIN_SIZE(&ch) );*/ if(BOOST_UNLIKELY(!dlmalloc_multialloc_arrays (n_elements, elem_sizes, sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, reinterpret_cast<dlmalloc_memchain *>(&chain)))){ boost::container::throw_bad_alloc(); } } void deallocate_many(multiallocation_chain &chain) BOOST_NOEXCEPT_OR_NOTHROW {/* dlmalloc_memchain ch; void *beg(&*chain.begin()), *last(&*chain.last()); size_t size(chain.size()); BOOST_CONTAINER_MEMCHAIN_INIT_FROM(&ch, beg, last, size); dlmalloc_multidealloc(&ch);*/ dlmalloc_multidealloc(reinterpret_cast<dlmalloc_memchain *>(&chain)); } //!Deallocates all free blocks of the pool static void deallocate_free_blocks() BOOST_NOEXCEPT_OR_NOTHROW { typedef dtl::shared_adaptive_node_pool <sizeof(T), NodesPerBlock, MaxFreeBlocks, OverheadPercent> shared_pool_t; typedef dtl::singleton_default<shared_pool_t> singleton_t; singleton_t::instance().deallocate_free_blocks(); } //!Swaps allocators. Does not throw. If each allocator is placed in a //!different memory segment, the result is undefined. friend void swap(adaptive_pool &, adaptive_pool &) BOOST_NOEXCEPT_OR_NOTHROW {} //!An allocator always compares to true, as memory allocated with one //!instance can be deallocated by another instance friend bool operator==(const adaptive_pool &, const adaptive_pool &) BOOST_NOEXCEPT_OR_NOTHROW { return true; } //!An allocator always compares to false, as memory allocated with one //!instance can be deallocated by another instance friend bool operator!=(const adaptive_pool &, const adaptive_pool &) BOOST_NOEXCEPT_OR_NOTHROW { return false; } private: pointer priv_allocation_command (allocation_type command, std::size_t limit_size ,size_type &prefer_in_recvd_out_size, pointer &reuse_ptr) { std::size_t const preferred_size = prefer_in_recvd_out_size; dlmalloc_command_ret_t ret = {0 , 0}; if(BOOST_UNLIKELY(limit_size > this->max_size() || preferred_size > this->max_size())){ return pointer(); } std::size_t l_size = limit_size*sizeof(T); std::size_t p_size = preferred_size*sizeof(T); std::size_t r_size; { void* reuse_ptr_void = reuse_ptr; ret = dlmalloc_allocation_command(command, sizeof(T), l_size, p_size, &r_size, reuse_ptr_void); reuse_ptr = ret.second ? static_cast<T*>(reuse_ptr_void) : 0; } prefer_in_recvd_out_size = r_size/sizeof(T); return (pointer)ret.first; } }; template < class T , std::size_t NodesPerBlock = ADP_nodes_per_block , std::size_t MaxFreeBlocks = ADP_max_free_blocks , std::size_t OverheadPercent = ADP_overhead_percent , unsigned Version = 2 > class private_adaptive_pool { //!If Version is 1, the allocator is a STL conforming allocator. If Version is 2, //!the allocator offers advanced expand in place and burst allocation capabilities. public: typedef unsigned int allocation_type; typedef private_adaptive_pool <T, NodesPerBlock, MaxFreeBlocks, OverheadPercent BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I Version) > self_t; static const std::size_t nodes_per_block = NodesPerBlock; static const std::size_t max_free_blocks = MaxFreeBlocks; static const std::size_t overhead_percent = OverheadPercent; static const std::size_t real_nodes_per_block = NodesPerBlock; BOOST_CONTAINER_DOCIGN(BOOST_STATIC_ASSERT((Version <=2))); typedef dtl::private_adaptive_node_pool <sizeof(T), NodesPerBlock, MaxFreeBlocks, OverheadPercent> pool_t; pool_t m_pool; public: //------- typedef T value_type; typedef T * pointer; typedef const T * const_pointer; typedef typename ::boost::container:: dtl::unvoid_ref<T>::type reference; typedef typename ::boost::container:: dtl::unvoid_ref<const T>::type const_reference; typedef std::size_t size_type; typedef std::ptrdiff_t difference_type; typedef boost::container::dtl:: version_type<self_t, Version> version; #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED typedef boost::container::dtl:: basic_multiallocation_chain<void*> multiallocation_chain_void; typedef boost::container::dtl:: transform_multiallocation_chain <multiallocation_chain_void, T> multiallocation_chain; #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED //!Obtains private_adaptive_pool from //!private_adaptive_pool template<class T2> struct rebind { typedef private_adaptive_pool < T2 , NodesPerBlock , MaxFreeBlocks , OverheadPercent BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I Version) > other; }; #ifndef BOOST_CONTAINER_DOXYGEN_INVOKED private: //!Not assignable from related private_adaptive_pool template<class T2, std::size_t N2, std::size_t F2, std::size_t O2, unsigned Version2> private_adaptive_pool& operator= (const private_adaptive_pool<T2, N2, F2, O2, Version2>&); #endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED public: //!Default constructor private_adaptive_pool() BOOST_NOEXCEPT_OR_NOTHROW {} //!Copy constructor from other private_adaptive_pool. private_adaptive_pool(const private_adaptive_pool &) BOOST_NOEXCEPT_OR_NOTHROW {} //!Copy assignment from other adaptive_pool. private_adaptive_pool & operator=(const private_adaptive_pool &) BOOST_NOEXCEPT_OR_NOTHROW { return *this; } //!Copy constructor from related private_adaptive_pool. template<class T2> private_adaptive_pool (const private_adaptive_pool<T2, NodesPerBlock, MaxFreeBlocks, OverheadPercent BOOST_CONTAINER_DOCIGN(BOOST_MOVE_I Version)> &) BOOST_NOEXCEPT_OR_NOTHROW {} //!Destructor ~private_adaptive_pool() BOOST_NOEXCEPT_OR_NOTHROW {} //!Returns the number of elements that could be allocated. //!Never throws size_type max_size() const BOOST_NOEXCEPT_OR_NOTHROW { return size_type(-1)/(2u*sizeof(T)); } //!Allocate memory for an array of count elements. //!Throws std::bad_alloc if there is no enough memory pointer allocate(size_type count, const void * = 0) { if(BOOST_UNLIKELY(count > size_type(-1)/(2u*sizeof(T)))) boost::container::throw_bad_alloc(); if(Version == 1 && count == 1){ return pointer(static_cast<T*>(m_pool.allocate_node())); } else{ return static_cast<pointer>(dlmalloc_malloc(count*sizeof(T))); } } //!Deallocate allocated memory. //!Never throws void deallocate(const pointer &ptr, size_type count) BOOST_NOEXCEPT_OR_NOTHROW { (void)count; if(Version == 1 && count == 1){ m_pool.deallocate_node(ptr); } else{ dlmalloc_free(ptr); } } pointer allocation_command(allocation_type command, size_type limit_size, size_type &prefer_in_recvd_out_size, pointer &reuse) { pointer ret = this->priv_allocation_command(command, limit_size, prefer_in_recvd_out_size, reuse); if(BOOST_UNLIKELY(!ret && !(command & BOOST_CONTAINER_NOTHROW_ALLOCATION))) boost::container::throw_bad_alloc(); return ret; } //!Returns maximum the number of objects the previously allocated memory //!pointed by p can hold. size_type size(pointer p) const BOOST_NOEXCEPT_OR_NOTHROW { return dlmalloc_size(p); } //!Allocates just one object. Memory allocated with this function //!must be deallocated only with deallocate_one(). //!Throws bad_alloc if there is no enough memory pointer allocate_one() { return (pointer)m_pool.allocate_node(); } //!Allocates many elements of size == 1. //!Elements must be individually deallocated with deallocate_one() void allocate_individual(std::size_t num_elements, multiallocation_chain &chain) { m_pool.allocate_nodes(num_elements, static_cast<typename pool_t::multiallocation_chain&>(chain)); } //!Deallocates memory previously allocated with allocate_one(). //!You should never use deallocate_one to deallocate memory allocated //!with other functions different from allocate_one(). Never throws void deallocate_one(pointer p) BOOST_NOEXCEPT_OR_NOTHROW { m_pool.deallocate_node(p); } void deallocate_individual(multiallocation_chain &chain) BOOST_NOEXCEPT_OR_NOTHROW { m_pool.deallocate_nodes(chain); } //!Allocates many elements of size elem_size. //!Elements must be individually deallocated with deallocate() void allocate_many(size_type elem_size, std::size_t n_elements, multiallocation_chain &chain) { BOOST_STATIC_ASSERT(( Version > 1 )); if(BOOST_UNLIKELY(!dlmalloc_multialloc_nodes (n_elements, elem_size*sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, reinterpret_cast<dlmalloc_memchain *>(&chain)))){ boost::container::throw_bad_alloc(); } } //!Allocates n_elements elements, each one of size elem_sizes[i] //!Elements must be individually deallocated with deallocate() void allocate_many(const size_type *elem_sizes, size_type n_elements, multiallocation_chain &chain) { BOOST_STATIC_ASSERT(( Version > 1 )); if(BOOST_UNLIKELY(!dlmalloc_multialloc_arrays (n_elements, elem_sizes, sizeof(T), BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, reinterpret_cast<dlmalloc_memchain *>(&chain)))){ boost::container::throw_bad_alloc(); } } void deallocate_many(multiallocation_chain &chain) BOOST_NOEXCEPT_OR_NOTHROW { dlmalloc_multidealloc(reinterpret_cast<dlmalloc_memchain *>(&chain)); } //!Deallocates all free blocks of the pool void deallocate_free_blocks() BOOST_NOEXCEPT_OR_NOTHROW { m_pool.deallocate_free_blocks(); } //!Swaps allocators. Does not throw. If each allocator is placed in a //!different memory segment, the result is undefined. friend void swap(private_adaptive_pool &, private_adaptive_pool &) BOOST_NOEXCEPT_OR_NOTHROW {} //!An allocator always compares to true, as memory allocated with one //!instance can be deallocated by another instance friend bool operator==(const private_adaptive_pool &, const private_adaptive_pool &) BOOST_NOEXCEPT_OR_NOTHROW { return true; } //!An allocator always compares to false, as memory allocated with one //!instance can be deallocated by another instance friend bool operator!=(const private_adaptive_pool &, const private_adaptive_pool &) BOOST_NOEXCEPT_OR_NOTHROW { return false; } private: pointer priv_allocation_command (allocation_type command, std::size_t limit_size ,size_type &prefer_in_recvd_out_size, pointer &reuse_ptr) { std::size_t const preferred_size = prefer_in_recvd_out_size; dlmalloc_command_ret_t ret = {0 , 0}; if(BOOST_UNLIKELY(limit_size > this->max_size() || preferred_size > this->max_size())){ return pointer(); } std::size_t l_size = limit_size*sizeof(T); std::size_t p_size = preferred_size*sizeof(T); std::size_t r_size; { void* reuse_ptr_void = reuse_ptr; ret = dlmalloc_allocation_command(command, sizeof(T), l_size, p_size, &r_size, reuse_ptr_void); reuse_ptr = ret.second ? static_cast<T*>(reuse_ptr_void) : 0; } prefer_in_recvd_out_size = r_size/sizeof(T); return (pointer)ret.first; } }; } //namespace container { } //namespace boost { #include <boost/container/detail/config_end.hpp> #endif //#ifndef BOOST_CONTAINER_ADAPTIVE_POOL_HPP
| ver. 1.6 |
Github
|
.
| PHP 8.2.30 | ??????????? ?????????: 0 |
proxy
|
phpinfo
|
???????????