forked from boostorg/container
Add Polymorphic Memory Resource utilities and rework the separately compiled library:
- Dlmalloc's based C function are boost_cont_xxx no longer exported, but wrapped into C++ linkage dlmalloc_xxx functions to effectively reuse Boost's dynamic library and autolink machinery instead of rewriting machinery to compile the C source file. - Refactored scoped_allocator_adaptor's construct logic as it was shared with polymorphic allocator's one. Moved common logic to detail/dispatch_uses_allocator.hpp. Refactored also scoped_allocator_adaptor test utilities to be reused with polymorphic_allocator tests.
This commit is contained in:
1 parent
77100c0bfc
commit
33d2f0f7af
110 files changed
+10143
-1160
No files matched your search
@@ -23,7 +23,6 @@
|
||||
#include <boost/container/detail/workaround.hpp>
|
||||
|
||||
#include <boost/intrusive/set.hpp>
|
||||
#include <boost/container/detail/alloc_lib_auto_link.hpp>
|
||||
#include <boost/container/detail/multiallocation_chain.hpp>
|
||||
#include <boost/container/detail/pool_common_alloc.hpp>
|
||||
#include <boost/container/detail/mutex.hpp>
|
||||
|
||||
@@ -15,27 +15,6 @@
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning (push)
|
||||
#pragma warning (disable : 4127)
|
||||
|
||||
/*
|
||||
we need to import/export our code only if the user has specifically
|
||||
asked for it by defining either BOOST_ALL_DYN_LINK if they want all boost
|
||||
libraries to be dynamically linked, or BOOST_CONTAINER_DYN_LINK
|
||||
if they want just this one to be dynamically liked:
|
||||
*/
|
||||
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_CONTAINER_DYN_LINK)
|
||||
|
||||
/* export if this is our own source, otherwise import: */
|
||||
#ifdef BOOST_CONTAINER_SOURCE
|
||||
# define BOOST_CONTAINER_DECL __declspec(dllexport)
|
||||
#else
|
||||
# define BOOST_CONTAINER_DECL __declspec(dllimport)
|
||||
#endif /* BOOST_CONTAINER_SOURCE */
|
||||
#endif /* DYN_LINK */
|
||||
#endif /* _MSC_VER */
|
||||
|
||||
/* if BOOST_CONTAINER_DECL isn't defined yet define it now: */
|
||||
#ifndef BOOST_CONTAINER_DECL
|
||||
#define BOOST_CONTAINER_DECL
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -215,14 +194,6 @@ typedef struct boost_cont_memchain_impl
|
||||
}while(0)\
|
||||
/**/
|
||||
|
||||
BOOST_CONTAINER_DECL size_t boost_cont_size(const void *p);
|
||||
|
||||
BOOST_CONTAINER_DECL void* boost_cont_malloc(size_t bytes);
|
||||
|
||||
BOOST_CONTAINER_DECL void boost_cont_free(void* mem);
|
||||
|
||||
BOOST_CONTAINER_DECL void* boost_cont_memalign(size_t bytes, size_t alignment);
|
||||
|
||||
/*!Indicates the all elements allocated by boost_cont_multialloc_nodes or boost_cont_multialloc_arrays
|
||||
must be contiguous.*/
|
||||
#define DL_MULTIALLOC_ALL_CONTIGUOUS ((size_t)(-1))
|
||||
@@ -231,22 +202,6 @@ BOOST_CONTAINER_DECL void* boost_cont_memalign(size_t bytes, size_t alignment);
|
||||
should be selected by those functions.*/
|
||||
#define DL_MULTIALLOC_DEFAULT_CONTIGUOUS ((size_t)(0))
|
||||
|
||||
BOOST_CONTAINER_DECL int boost_cont_multialloc_nodes
|
||||
(size_t n_elements, size_t elem_size, size_t contiguous_elements, boost_cont_memchain *pchain);
|
||||
|
||||
BOOST_CONTAINER_DECL int boost_cont_multialloc_arrays
|
||||
(size_t n_elements, const size_t *sizes, size_t sizeof_element, size_t contiguous_elements, boost_cont_memchain *pchain);
|
||||
|
||||
BOOST_CONTAINER_DECL void boost_cont_multidealloc(boost_cont_memchain *pchain);
|
||||
|
||||
BOOST_CONTAINER_DECL size_t boost_cont_footprint();
|
||||
|
||||
BOOST_CONTAINER_DECL size_t boost_cont_allocated_memory();
|
||||
|
||||
BOOST_CONTAINER_DECL size_t boost_cont_chunksize(const void *p);
|
||||
|
||||
BOOST_CONTAINER_DECL int boost_cont_all_deallocated();
|
||||
|
||||
typedef struct boost_cont_malloc_stats_impl
|
||||
{
|
||||
size_t max_system_bytes;
|
||||
@@ -254,26 +209,6 @@ typedef struct boost_cont_malloc_stats_impl
|
||||
size_t in_use_bytes;
|
||||
} boost_cont_malloc_stats_t;
|
||||
|
||||
BOOST_CONTAINER_DECL boost_cont_malloc_stats_t boost_cont_malloc_stats();
|
||||
|
||||
BOOST_CONTAINER_DECL size_t boost_cont_in_use_memory();
|
||||
|
||||
BOOST_CONTAINER_DECL int boost_cont_trim(size_t pad);
|
||||
|
||||
BOOST_CONTAINER_DECL int boost_cont_mallopt
|
||||
(int parameter_number, int parameter_value);
|
||||
|
||||
BOOST_CONTAINER_DECL int boost_cont_grow
|
||||
(void* oldmem, size_t minbytes, size_t maxbytes, size_t *received);
|
||||
|
||||
BOOST_CONTAINER_DECL int boost_cont_shrink
|
||||
(void* oldmem, size_t minbytes, size_t maxbytes, size_t *received, int do_commit);
|
||||
|
||||
BOOST_CONTAINER_DECL void* boost_cont_alloc
|
||||
(size_t minbytes, size_t preferred_bytes, size_t *received_bytes);
|
||||
|
||||
BOOST_CONTAINER_DECL int boost_cont_malloc_check();
|
||||
|
||||
typedef unsigned int allocation_type;
|
||||
|
||||
enum
|
||||
@@ -303,7 +238,50 @@ typedef struct boost_cont_command_ret_impl
|
||||
int second;
|
||||
}boost_cont_command_ret_t;
|
||||
|
||||
BOOST_CONTAINER_DECL boost_cont_command_ret_t boost_cont_allocation_command
|
||||
size_t boost_cont_size(const void *p);
|
||||
|
||||
void* boost_cont_malloc(size_t bytes);
|
||||
|
||||
void boost_cont_free(void* mem);
|
||||
|
||||
void* boost_cont_memalign(size_t bytes, size_t alignment);
|
||||
|
||||
int boost_cont_multialloc_nodes
|
||||
(size_t n_elements, size_t elem_size, size_t contiguous_elements, boost_cont_memchain *pchain);
|
||||
|
||||
int boost_cont_multialloc_arrays
|
||||
(size_t n_elements, const size_t *sizes, size_t sizeof_element, size_t contiguous_elements, boost_cont_memchain *pchain);
|
||||
|
||||
void boost_cont_multidealloc(boost_cont_memchain *pchain);
|
||||
|
||||
size_t boost_cont_footprint();
|
||||
|
||||
size_t boost_cont_allocated_memory();
|
||||
|
||||
size_t boost_cont_chunksize(const void *p);
|
||||
|
||||
int boost_cont_all_deallocated();
|
||||
|
||||
boost_cont_malloc_stats_t boost_cont_malloc_stats();
|
||||
|
||||
size_t boost_cont_in_use_memory();
|
||||
|
||||
int boost_cont_trim(size_t pad);
|
||||
|
||||
int boost_cont_mallopt(int parameter_number, int parameter_value);
|
||||
|
||||
int boost_cont_grow
|
||||
(void* oldmem, size_t minbytes, size_t maxbytes, size_t *received);
|
||||
|
||||
int boost_cont_shrink
|
||||
(void* oldmem, size_t minbytes, size_t maxbytes, size_t *received, int do_commit);
|
||||
|
||||
void* boost_cont_alloc
|
||||
(size_t minbytes, size_t preferred_bytes, size_t *received_bytes);
|
||||
|
||||
int boost_cont_malloc_check();
|
||||
|
||||
boost_cont_command_ret_t boost_cont_allocation_command
|
||||
( allocation_type command
|
||||
, size_t sizeof_object
|
||||
, size_t limit_objects
|
||||
@@ -312,7 +290,17 @@ BOOST_CONTAINER_DECL boost_cont_command_ret_t boost_cont_allocation_command
|
||||
, void *reuse_ptr
|
||||
);
|
||||
|
||||
BOOST_CONTAINER_DECL int boost_cont_mallopt(int param_number, int value);
|
||||
void *boost_cont_sync_create();
|
||||
|
||||
void boost_cont_sync_destroy(void *sync);
|
||||
|
||||
int boost_cont_sync_lock(void *sync);
|
||||
|
||||
void boost_cont_sync_unlock(void *sync);
|
||||
|
||||
int boost_cont_global_sync_lock();
|
||||
|
||||
void boost_cont_global_sync_unlock();
|
||||
|
||||
#ifdef __cplusplus
|
||||
} //extern "C" {
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (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_DETAIL_BOOST_CONT_EXT_AUTO_LINK_HPP
|
||||
#define BOOST_CONTAINER_DETAIL_BOOST_CONT_EXT_AUTO_LINK_HPP
|
||||
|
||||
#ifndef BOOST_CONFIG_HPP
|
||||
# include <boost/config.hpp>
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_HAS_PRAGMA_ONCE)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/container/detail/auto_link.hpp>
|
||||
#include <boost/container/detail/alloc_lib.h>
|
||||
|
||||
#endif //#ifndef BOOST_CONTAINER_DETAIL_BOOST_CONT_EXT_AUTO_LINK_HPP
|
||||
@@ -18,6 +18,13 @@
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
//Define BOOST_CONTAINER_DYNAMIC_LINKING which is independent from BOOST_*_NO_LIB
|
||||
//and is needed is some tests that need to disable some checks (like operator new replacements)
|
||||
//that don't work across DLL boundaries
|
||||
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_CONTAINER_DYN_LINK)
|
||||
# define BOOST_CONTAINER_DYNAMIC_LINKING
|
||||
#endif
|
||||
|
||||
//
|
||||
// Automatically link to the correct build variant where possible.
|
||||
//
|
||||
@@ -27,12 +34,14 @@
|
||||
// once it's done with it:
|
||||
//
|
||||
#define BOOST_LIB_NAME boost_container
|
||||
|
||||
//
|
||||
// If we're importing code from a dll, then tell auto_link.hpp about it:
|
||||
//
|
||||
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_CONTAINER_DYN_LINK)
|
||||
#if defined(BOOST_CONTAINER_DYNAMIC_LINKING)
|
||||
# define BOOST_DYN_LINK
|
||||
#endif
|
||||
|
||||
//
|
||||
// And include the header that does the work:
|
||||
//
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2015-2015. 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_DETAIL_BLOCK_LIST_HEADER
|
||||
#define BOOST_CONTAINER_DETAIL_BLOCK_LIST_HEADER
|
||||
|
||||
#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/pmr/memory_resource.hpp>
|
||||
#include <boost/container/throw_exception.hpp>
|
||||
#include <boost/intrusive/circular_list_algorithms.hpp>
|
||||
#include <boost/move/detail/type_traits.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace container {
|
||||
namespace pmr {
|
||||
|
||||
struct list_node
|
||||
{
|
||||
list_node *next;
|
||||
list_node *previous;
|
||||
};
|
||||
|
||||
struct list_node_traits
|
||||
{
|
||||
typedef list_node node;
|
||||
typedef list_node* node_ptr;
|
||||
typedef const list_node* const_node_ptr;
|
||||
|
||||
static node_ptr get_next(const_node_ptr n)
|
||||
{ return n->next; }
|
||||
|
||||
static node_ptr get_previous(const_node_ptr n)
|
||||
{ return n->previous; }
|
||||
|
||||
static void set_next(const node_ptr & n, const node_ptr & next)
|
||||
{ n->next = next; }
|
||||
|
||||
static void set_previous(const node_ptr & n, const node_ptr & previous)
|
||||
{ n->previous = previous; }
|
||||
};
|
||||
|
||||
struct block_list_header
|
||||
: public list_node
|
||||
{
|
||||
std::size_t size;
|
||||
};
|
||||
|
||||
typedef bi::circular_list_algorithms<list_node_traits> list_algo;
|
||||
|
||||
|
||||
template<class DerivedFromBlockListHeader = block_list_header>
|
||||
class block_list_base
|
||||
{
|
||||
list_node m_list;
|
||||
|
||||
static const std::size_t MaxAlignMinus1 = memory_resource::max_align-1u;
|
||||
|
||||
public:
|
||||
|
||||
static const std::size_t header_size = std::size_t(sizeof(DerivedFromBlockListHeader) + MaxAlignMinus1) & std::size_t(~MaxAlignMinus1);
|
||||
|
||||
explicit block_list_base()
|
||||
{ list_algo::init_header(&m_list); }
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
block_list_base(const block_list_base&) = delete;
|
||||
block_list_base operator=(const block_list_base&) = delete;
|
||||
#else
|
||||
private:
|
||||
block_list_base (const block_list_base&);
|
||||
block_list_base operator=(const block_list_base&);
|
||||
public:
|
||||
#endif
|
||||
|
||||
~block_list_base()
|
||||
{}
|
||||
|
||||
void *allocate(std::size_t size, memory_resource &mr)
|
||||
{
|
||||
if((size_t(-1) - header_size) < size)
|
||||
throw_bad_alloc();
|
||||
void *p = mr.allocate(size+header_size);
|
||||
block_list_header &mb = *::new((void*)p) DerivedFromBlockListHeader;
|
||||
mb.size = size+header_size;
|
||||
list_algo::link_after(&m_list, &mb);
|
||||
return (char *)p + header_size;
|
||||
}
|
||||
|
||||
void deallocate(void *p, memory_resource &mr) BOOST_NOEXCEPT
|
||||
{
|
||||
DerivedFromBlockListHeader *pheader = static_cast<DerivedFromBlockListHeader*>
|
||||
(static_cast<void*>((char*)p - header_size));
|
||||
list_algo::unlink(pheader);
|
||||
const std::size_t size = pheader->size;
|
||||
static_cast<DerivedFromBlockListHeader*>(pheader)->~DerivedFromBlockListHeader();
|
||||
mr.deallocate(pheader, size, memory_resource::max_align);
|
||||
}
|
||||
|
||||
void release(memory_resource &mr) BOOST_NOEXCEPT
|
||||
{
|
||||
list_node *n = list_algo::node_traits::get_next(&m_list);
|
||||
while(n != &m_list){
|
||||
DerivedFromBlockListHeader &d = static_cast<DerivedFromBlockListHeader&>(*n);
|
||||
n = list_algo::node_traits::get_next(n);
|
||||
std::size_t size = d.size;
|
||||
d.~DerivedFromBlockListHeader();
|
||||
mr.deallocate(reinterpret_cast<char*>(&d), size, memory_resource::max_align);
|
||||
}
|
||||
list_algo::init_header(&m_list);
|
||||
}
|
||||
};
|
||||
|
||||
} //namespace pmr {
|
||||
} //namespace container {
|
||||
} //namespace boost {
|
||||
|
||||
#include <boost/container/detail/config_end.hpp>
|
||||
|
||||
#endif //BOOST_CONTAINER_DETAIL_BLOCK_LIST_HEADER
|
||||
@@ -0,0 +1,157 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2015-2015. 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_DETAIL_BLOCK_SLIST_HEADER
|
||||
#define BOOST_CONTAINER_DETAIL_BLOCK_SLIST_HEADER
|
||||
|
||||
#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/pmr/memory_resource.hpp>
|
||||
#include <boost/container/throw_exception.hpp>
|
||||
|
||||
#include <boost/move/detail/type_traits.hpp>
|
||||
#include <boost/intrusive/linear_slist_algorithms.hpp>
|
||||
#include <boost/assert.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace container {
|
||||
namespace pmr {
|
||||
|
||||
struct slist_node
|
||||
{
|
||||
slist_node *next;
|
||||
};
|
||||
|
||||
struct slist_node_traits
|
||||
{
|
||||
typedef slist_node node;
|
||||
typedef slist_node* node_ptr;
|
||||
typedef const slist_node* const_node_ptr;
|
||||
|
||||
static node_ptr get_next(const_node_ptr n)
|
||||
{ return n->next; }
|
||||
|
||||
static void set_next(const node_ptr & n, const node_ptr & next)
|
||||
{ n->next = next; }
|
||||
};
|
||||
|
||||
struct block_slist_header
|
||||
: public slist_node
|
||||
{
|
||||
std::size_t size;
|
||||
};
|
||||
|
||||
typedef bi::linear_slist_algorithms<slist_node_traits> slist_algo;
|
||||
|
||||
template<class DerivedFromBlockSlistHeader = block_slist_header>
|
||||
class block_slist_base
|
||||
{
|
||||
slist_node m_slist;
|
||||
|
||||
static const std::size_t MaxAlignMinus1 = memory_resource::max_align-1u;
|
||||
|
||||
public:
|
||||
|
||||
static const std::size_t header_size = std::size_t(sizeof(DerivedFromBlockSlistHeader) + MaxAlignMinus1) & std::size_t(~MaxAlignMinus1);
|
||||
|
||||
explicit block_slist_base()
|
||||
{ slist_algo::init_header(&m_slist); }
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
block_slist_base(const block_slist_base&) = delete;
|
||||
block_slist_base operator=(const block_slist_base&) = delete;
|
||||
#else
|
||||
private:
|
||||
block_slist_base (const block_slist_base&);
|
||||
block_slist_base operator=(const block_slist_base&);
|
||||
public:
|
||||
#endif
|
||||
|
||||
~block_slist_base()
|
||||
{}
|
||||
|
||||
void *allocate(std::size_t size, memory_resource &mr)
|
||||
{
|
||||
if((size_t(-1) - header_size) < size)
|
||||
throw_bad_alloc();
|
||||
void *p = mr.allocate(size+header_size);
|
||||
block_slist_header &mb = *::new((void*)p) DerivedFromBlockSlistHeader;
|
||||
mb.size = size+header_size;
|
||||
slist_algo::link_after(&m_slist, &mb);
|
||||
return (char *)p + header_size;
|
||||
}
|
||||
|
||||
void release(memory_resource &mr) BOOST_NOEXCEPT
|
||||
{
|
||||
slist_node *n = slist_algo::node_traits::get_next(&m_slist);
|
||||
while(n){
|
||||
DerivedFromBlockSlistHeader &d = static_cast<DerivedFromBlockSlistHeader&>(*n);
|
||||
n = slist_algo::node_traits::get_next(n);
|
||||
std::size_t size = d.block_slist_header::size;
|
||||
d.~DerivedFromBlockSlistHeader();
|
||||
mr.deallocate(reinterpret_cast<char*>(&d), size, memory_resource::max_align);
|
||||
}
|
||||
slist_algo::init_header(&m_slist);
|
||||
}
|
||||
};
|
||||
|
||||
class block_slist
|
||||
: public block_slist_base<>
|
||||
{
|
||||
memory_resource &m_upstream_rsrc;
|
||||
|
||||
public:
|
||||
|
||||
explicit block_slist(memory_resource &upstream_rsrc)
|
||||
: block_slist_base<>(), m_upstream_rsrc(upstream_rsrc)
|
||||
{}
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
block_slist(const block_slist&) = delete;
|
||||
block_slist operator=(const block_slist&) = delete;
|
||||
#else
|
||||
private:
|
||||
block_slist (const block_slist&);
|
||||
block_slist operator=(const block_slist&);
|
||||
public:
|
||||
#endif
|
||||
|
||||
~block_slist()
|
||||
{ this->release(); }
|
||||
|
||||
void *allocate(std::size_t size)
|
||||
{ return this->block_slist_base<>::allocate(size, m_upstream_rsrc); }
|
||||
|
||||
void release() BOOST_NOEXCEPT
|
||||
{ return this->block_slist_base<>::release(m_upstream_rsrc); }
|
||||
|
||||
memory_resource& upstream_resource() const BOOST_NOEXCEPT
|
||||
{ return m_upstream_rsrc; }
|
||||
};
|
||||
|
||||
} //namespace pmr {
|
||||
} //namespace container {
|
||||
} //namespace boost {
|
||||
|
||||
#include <boost/container/detail/config_end.hpp>
|
||||
|
||||
#endif //BOOST_CONTAINER_DETAIL_BLOCK_SLIST_HEADER
|
||||
@@ -25,6 +25,7 @@
|
||||
#pragma warning (disable : 4267) // conversion from "X" to "Y", possible loss of data
|
||||
#pragma warning (disable : 4275) // non DLL-interface classkey "identifier" used as base for DLL-interface classkey "identifier"
|
||||
#pragma warning (disable : 4284) // odd return type for operator->
|
||||
#pragma warning (disable : 4290) // C++ exception specification ignored except to indicate a function is not __declspec(nothrow)
|
||||
#pragma warning (disable : 4324) // structure was padded due to __declspec(align(
|
||||
#pragma warning (disable : 4345) // behavior change: an object of POD type constructed with an initializer of the form () will be default-initialized
|
||||
#pragma warning (disable : 4355) // "this" : used in base member initializer list
|
||||
|
||||
@@ -0,0 +1,293 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2015-2015. 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_DISPATCH_USES_ALLOCATOR_HPP
|
||||
#define BOOST_CONTAINER_DISPATCH_USES_ALLOCATOR_HPP
|
||||
|
||||
#if defined (_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/container/detail/config_begin.hpp>
|
||||
#include <boost/container/detail/workaround.hpp>
|
||||
|
||||
#include <boost/container/allocator_traits.hpp>
|
||||
#include <boost/container/uses_allocator.hpp>
|
||||
|
||||
#include <boost/container/detail/addressof.hpp>
|
||||
#include <boost/container/detail/mpl.hpp>
|
||||
#include <boost/container/detail/pair.hpp>
|
||||
#include <boost/container/detail/type_traits.hpp>
|
||||
|
||||
#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
#include <boost/move/detail/fwd_macros.hpp>
|
||||
#endif
|
||||
#include <boost/move/utility_core.hpp>
|
||||
|
||||
#include <boost/core/no_exceptions_support.hpp>
|
||||
|
||||
namespace boost { namespace container {
|
||||
|
||||
namespace container_detail {
|
||||
|
||||
|
||||
// Check if we can detect is_convertible using advanced SFINAE expressions
|
||||
#if !defined(BOOST_NO_CXX11_DECLTYPE) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
//! Code inspired by Mathias Gaunard's is_convertible.cpp found in the Boost mailing list
|
||||
//! http://boost.2283326.n4.nabble.com/type-traits-is-constructible-when-decltype-is-supported-td3575452.html
|
||||
//! Thanks Mathias!
|
||||
|
||||
//With variadic templates, we need a single class to implement the trait
|
||||
template<class T, class ...Args>
|
||||
struct is_constructible
|
||||
{
|
||||
typedef char yes_type;
|
||||
struct no_type
|
||||
{ char padding[2]; };
|
||||
|
||||
template<std::size_t N>
|
||||
struct dummy;
|
||||
|
||||
template<class X>
|
||||
static decltype(X(boost::move_detail::declval<Args>()...), true_type()) test(int);
|
||||
|
||||
template<class X>
|
||||
static no_type test(...);
|
||||
|
||||
static const bool value = sizeof(test<T>(0)) == sizeof(yes_type);
|
||||
};
|
||||
|
||||
template <class T, class InnerAlloc, class ...Args>
|
||||
struct is_constructible_with_allocator_prefix
|
||||
: is_constructible<T, allocator_arg_t, InnerAlloc, Args...>
|
||||
{};
|
||||
|
||||
#else // #if !defined(BOOST_NO_SFINAE_EXPR) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
//Without advanced SFINAE expressions, we can't use is_constructible
|
||||
//so backup to constructible_with_allocator_xxx
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
template <class T, class InnerAlloc, class ...Args>
|
||||
struct is_constructible_with_allocator_prefix
|
||||
: constructible_with_allocator_prefix<T>
|
||||
{};
|
||||
|
||||
template <class T, class InnerAlloc, class ...Args>
|
||||
struct is_constructible_with_allocator_suffix
|
||||
: constructible_with_allocator_suffix<T>
|
||||
{};
|
||||
|
||||
#else // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
template <class T, class InnerAlloc, BOOST_MOVE_CLASSDFLT9>
|
||||
struct is_constructible_with_allocator_prefix
|
||||
: constructible_with_allocator_prefix<T>
|
||||
{};
|
||||
|
||||
template <class T, class InnerAlloc, BOOST_MOVE_CLASSDFLT9>
|
||||
struct is_constructible_with_allocator_suffix
|
||||
: constructible_with_allocator_suffix<T>
|
||||
{};
|
||||
|
||||
#endif // #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
#endif // #if !defined(BOOST_NO_SFINAE_EXPR)
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, typename T
|
||||
, class ...Args
|
||||
>
|
||||
inline typename container_detail::enable_if_and
|
||||
< void
|
||||
, container_detail::is_not_pair<T>
|
||||
, container_detail::not_< uses_allocator<T, ArgAlloc> >
|
||||
>::type dispatch_uses_allocator
|
||||
( ConstructAlloc & construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p, BOOST_FWD_REF(Args)...args)
|
||||
{
|
||||
(void)arg_alloc;
|
||||
allocator_traits<ConstructAlloc>::construct(construct_alloc, p, ::boost::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// allocator_arg_t
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, typename T
|
||||
, class ...Args
|
||||
>
|
||||
inline typename container_detail::enable_if_and
|
||||
< void
|
||||
, container_detail::is_not_pair<T>
|
||||
, uses_allocator<T, ArgAlloc>
|
||||
, is_constructible_with_allocator_prefix<T, ArgAlloc, Args...>
|
||||
>::type dispatch_uses_allocator
|
||||
( ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p, BOOST_FWD_REF(Args) ...args)
|
||||
{
|
||||
allocator_traits<ConstructAlloc>::construct
|
||||
( construct_alloc, p, allocator_arg
|
||||
, ::boost::forward<ArgAlloc>(arg_alloc), ::boost::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
// allocator suffix
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, typename T
|
||||
, class ...Args
|
||||
>
|
||||
inline typename container_detail::enable_if_and
|
||||
< void
|
||||
, container_detail::is_not_pair<T>
|
||||
, uses_allocator<T, ArgAlloc>
|
||||
, container_detail::not_<is_constructible_with_allocator_prefix<T, ArgAlloc, Args...> >
|
||||
>::type dispatch_uses_allocator
|
||||
( ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p, BOOST_FWD_REF(Args)...args)
|
||||
{
|
||||
allocator_traits<ConstructAlloc>::construct
|
||||
(construct_alloc, p, ::boost::forward<Args>(args)..., ::boost::forward<ArgAlloc>(arg_alloc));
|
||||
}
|
||||
|
||||
#else //#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
#define BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE(N) \
|
||||
template <typename ConstructAlloc, typename ArgAlloc, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
||||
inline typename container_detail::enable_if_and\
|
||||
< void\
|
||||
, container_detail::is_not_pair<T>\
|
||||
, container_detail::not_<uses_allocator<T, ArgAlloc> >\
|
||||
>::type\
|
||||
dispatch_uses_allocator\
|
||||
(ConstructAlloc &construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
|
||||
{\
|
||||
(void)arg_alloc;\
|
||||
allocator_traits<ConstructAlloc>::construct(construct_alloc, p BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
|
||||
}\
|
||||
//
|
||||
BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE)
|
||||
#undef BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE
|
||||
|
||||
#define BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE(N) \
|
||||
template < typename ConstructAlloc, typename ArgAlloc, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
||||
inline typename container_detail::enable_if_and\
|
||||
< void\
|
||||
, container_detail::is_not_pair<T>\
|
||||
, uses_allocator<T, ArgAlloc>\
|
||||
, is_constructible_with_allocator_prefix<T, ArgAlloc BOOST_MOVE_I##N BOOST_MOVE_TARG##N>\
|
||||
>::type\
|
||||
dispatch_uses_allocator\
|
||||
(ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
|
||||
{\
|
||||
allocator_traits<ConstructAlloc>::construct\
|
||||
(construct_alloc, p, allocator_arg, ::boost::forward<ArgAlloc>(arg_alloc) BOOST_MOVE_I##N BOOST_MOVE_FWD##N);\
|
||||
}\
|
||||
//
|
||||
BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE)
|
||||
#undef BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE
|
||||
|
||||
#define BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE(N) \
|
||||
template < typename ConstructAlloc, typename ArgAlloc, typename T BOOST_MOVE_I##N BOOST_MOVE_CLASS##N >\
|
||||
inline typename container_detail::enable_if_and\
|
||||
< void\
|
||||
, container_detail::is_not_pair<T>\
|
||||
, uses_allocator<T, ArgAlloc>\
|
||||
, container_detail::not_<is_constructible_with_allocator_prefix<T, ArgAlloc BOOST_MOVE_I##N BOOST_MOVE_TARG##N> >\
|
||||
>::type\
|
||||
dispatch_uses_allocator\
|
||||
(ConstructAlloc& construct_alloc, BOOST_FWD_REF(ArgAlloc) arg_alloc, T* p BOOST_MOVE_I##N BOOST_MOVE_UREF##N)\
|
||||
{\
|
||||
allocator_traits<ConstructAlloc>::construct\
|
||||
(construct_alloc, p BOOST_MOVE_I##N BOOST_MOVE_FWD##N, ::boost::forward<ArgAlloc>(arg_alloc));\
|
||||
}\
|
||||
//
|
||||
BOOST_MOVE_ITERATE_0TO9(BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE)
|
||||
#undef BOOST_CONTAINER_SCOPED_ALLOCATOR_DISPATCH_USES_ALLOCATOR_CODE
|
||||
|
||||
#endif //#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
|
||||
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, typename Pair
|
||||
> inline
|
||||
BOOST_CONTAINER_DOC1ST(void, typename container_detail::enable_if<container_detail::is_pair<Pair> >::type)
|
||||
dispatch_uses_allocator
|
||||
( ConstructAlloc & construct_alloc
|
||||
, ArgAlloc & arg_alloc
|
||||
, Pair* p)
|
||||
{
|
||||
(dispatch_uses_allocator)(construct_alloc, arg_alloc, container_detail::addressof(p->first));
|
||||
BOOST_TRY{
|
||||
(dispatch_uses_allocator)(construct_alloc, arg_alloc, container_detail::addressof(p->second));
|
||||
}
|
||||
BOOST_CATCH(...) {
|
||||
allocator_traits<ConstructAlloc>::destroy(construct_alloc, container_detail::addressof(p->first));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
}
|
||||
|
||||
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, class Pair, class U, class V>
|
||||
BOOST_CONTAINER_DOC1ST(void, typename container_detail::enable_if<container_detail::is_pair<Pair> >::type)
|
||||
dispatch_uses_allocator
|
||||
( ConstructAlloc & construct_alloc
|
||||
, ArgAlloc & arg_alloc
|
||||
, Pair* p, BOOST_FWD_REF(U) x, BOOST_FWD_REF(V) y)
|
||||
{
|
||||
(dispatch_uses_allocator)(construct_alloc, arg_alloc, container_detail::addressof(p->first), ::boost::forward<U>(x));
|
||||
BOOST_TRY{
|
||||
(dispatch_uses_allocator)(construct_alloc, arg_alloc, container_detail::addressof(p->second), ::boost::forward<V>(y));
|
||||
}
|
||||
BOOST_CATCH(...){
|
||||
allocator_traits<ConstructAlloc>::destroy(construct_alloc, container_detail::addressof(p->first));
|
||||
BOOST_RETHROW
|
||||
}
|
||||
BOOST_CATCH_END
|
||||
}
|
||||
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, class Pair, class Pair2>
|
||||
BOOST_CONTAINER_DOC1ST(void, typename container_detail::enable_if< container_detail::is_pair<Pair> >::type)
|
||||
dispatch_uses_allocator
|
||||
(ConstructAlloc & construct_alloc
|
||||
, ArgAlloc & arg_alloc
|
||||
, Pair* p, Pair2& x)
|
||||
{ (dispatch_uses_allocator)(construct_alloc, arg_alloc, p, x.first, x.second); }
|
||||
|
||||
template < typename ConstructAlloc
|
||||
, typename ArgAlloc
|
||||
, class Pair, class Pair2>
|
||||
typename container_detail::enable_if_and
|
||||
< void
|
||||
, container_detail::is_pair<Pair>
|
||||
, container_detail::not_<boost::move_detail::is_reference<Pair2> > >::type //This is needed for MSVC10 and ambiguous overloads
|
||||
dispatch_uses_allocator
|
||||
(ConstructAlloc & construct_alloc
|
||||
, ArgAlloc & arg_alloc
|
||||
, Pair* p, BOOST_RV_REF_BEG Pair2 BOOST_RV_REF_END x)
|
||||
{ (dispatch_uses_allocator)(construct_alloc, arg_alloc, p, ::boost::move(x.first), ::boost::move(x.second)); }
|
||||
|
||||
//template <typename ConstructAlloc, typename ArgAlloc, class Pair, class Pair2>
|
||||
//void dispatch_uses_allocator( ConstructAlloc & construct_alloc, ArgAlloc & arg_alloc
|
||||
// , pair<T1, T2>* p, piecewise_construct_t, tuple<Args1...> x, tuple<Args2...> y);
|
||||
|
||||
} //namespace container_detail
|
||||
|
||||
}} // namespace boost { namespace container {
|
||||
|
||||
#include <boost/container/detail/config_end.hpp>
|
||||
|
||||
#endif // BOOST_CONTAINER_DISPATCH_USES_ALLOCATOR_HPP
|
||||
@@ -0,0 +1,103 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2015-2015. 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_DETAIL_ALLOC_LIB_HPP
|
||||
#define BOOST_CONTAINER_DETAIL_ALLOC_LIB_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/detail/auto_link.hpp>
|
||||
|
||||
#include <boost/container/detail/alloc_lib.h>
|
||||
|
||||
namespace boost{
|
||||
namespace container{
|
||||
|
||||
typedef boost_cont_command_ret_t dlmalloc_command_ret_t;
|
||||
typedef boost_cont_memchain dlmalloc_memchain;
|
||||
typedef boost_cont_memchain_it dlmalloc_memchain_it;
|
||||
typedef boost_cont_malloc_stats_t dlmalloc_malloc_stats_t;
|
||||
|
||||
BOOST_CONTAINER_DECL size_t dlmalloc_size(const void *p);
|
||||
|
||||
BOOST_CONTAINER_DECL void* dlmalloc_malloc(size_t bytes);
|
||||
|
||||
BOOST_CONTAINER_DECL void dlmalloc_free(void* mem);
|
||||
|
||||
BOOST_CONTAINER_DECL void* dlmalloc_memalign(size_t bytes, size_t alignment);
|
||||
|
||||
BOOST_CONTAINER_DECL int dlmalloc_multialloc_nodes
|
||||
(size_t n_elements, size_t elem_size, size_t contiguous_elements, boost_cont_memchain *pchain);
|
||||
|
||||
BOOST_CONTAINER_DECL int dlmalloc_multialloc_arrays
|
||||
(size_t n_elements, const size_t *sizes, size_t sizeof_element, size_t contiguous_elements, boost_cont_memchain *pchain);
|
||||
|
||||
BOOST_CONTAINER_DECL void dlmalloc_multidealloc(boost_cont_memchain *pchain);
|
||||
|
||||
BOOST_CONTAINER_DECL size_t dlmalloc_footprint();
|
||||
|
||||
BOOST_CONTAINER_DECL size_t dlmalloc_allocated_memory();
|
||||
|
||||
BOOST_CONTAINER_DECL size_t dlmalloc_chunksize(const void *p);
|
||||
|
||||
BOOST_CONTAINER_DECL int dlmalloc_all_deallocated();
|
||||
|
||||
BOOST_CONTAINER_DECL boost_cont_malloc_stats_t dlmalloc_malloc_stats();
|
||||
|
||||
BOOST_CONTAINER_DECL size_t dlmalloc_in_use_memory();
|
||||
|
||||
BOOST_CONTAINER_DECL int dlmalloc_trim(size_t pad);
|
||||
|
||||
BOOST_CONTAINER_DECL int dlmalloc_mallopt(int parameter_number, int parameter_value);
|
||||
|
||||
BOOST_CONTAINER_DECL int dlmalloc_grow(void* oldmem, size_t minbytes, size_t maxbytes, size_t *received);
|
||||
|
||||
BOOST_CONTAINER_DECL int dlmalloc_shrink(void* oldmem, size_t minbytes, size_t maxbytes, size_t *received, int do_commit);
|
||||
|
||||
BOOST_CONTAINER_DECL void* dlmalloc_alloc(size_t minbytes, size_t preferred_bytes, size_t *received_bytes);
|
||||
|
||||
BOOST_CONTAINER_DECL int dlmalloc_malloc_check();
|
||||
|
||||
BOOST_CONTAINER_DECL boost_cont_command_ret_t dlmalloc_allocation_command
|
||||
( allocation_type command
|
||||
, size_t sizeof_object
|
||||
, size_t limit_objects
|
||||
, size_t preferred_objects
|
||||
, size_t *received_objects
|
||||
, void *reuse_ptr
|
||||
);
|
||||
|
||||
BOOST_CONTAINER_DECL int dlmalloc_mallopt(int param_number, int value);
|
||||
|
||||
BOOST_CONTAINER_DECL void *dlmalloc_sync_create();
|
||||
|
||||
BOOST_CONTAINER_DECL void dlmalloc_sync_destroy(void *sync);
|
||||
|
||||
BOOST_CONTAINER_DECL bool dlmalloc_sync_lock(void *sync);
|
||||
|
||||
BOOST_CONTAINER_DECL void dlmalloc_sync_unlock(void *sync);
|
||||
|
||||
BOOST_CONTAINER_DECL bool dlmalloc_global_sync_lock();
|
||||
|
||||
BOOST_CONTAINER_DECL void dlmalloc_global_sync_unlock();
|
||||
|
||||
} //namespace container{
|
||||
} //namespace boost{
|
||||
|
||||
#include <boost/container/detail/config_end.hpp>
|
||||
|
||||
#endif //BOOST_CONTAINER_DETAIL_ALLOC_LIB_HPP
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include <boost/intrusive/slist.hpp>
|
||||
#include <boost/container/detail/pool_common.hpp>
|
||||
#include <boost/container/detail/alloc_lib.h>
|
||||
#include <boost/container/detail/dlmalloc.hpp>
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost{
|
||||
@@ -44,15 +44,15 @@ struct fake_segment_manager
|
||||
typedef boost::container::container_detail::
|
||||
basic_multiallocation_chain<void*> multiallocation_chain;
|
||||
static void deallocate(void_pointer p)
|
||||
{ boost_cont_free(p); }
|
||||
{ dlmalloc_free(p); }
|
||||
|
||||
static void deallocate_many(multiallocation_chain &chain)
|
||||
{
|
||||
std::size_t size = chain.size();
|
||||
std::pair<void*, void*> ptrs = chain.extract_data();
|
||||
boost_cont_memchain dlchain;
|
||||
dlmalloc_memchain dlchain;
|
||||
BOOST_CONTAINER_MEMCHAIN_INIT_FROM(&dlchain, ptrs.first, ptrs.second, size);
|
||||
boost_cont_multidealloc(&dlchain);
|
||||
dlmalloc_multidealloc(&dlchain);
|
||||
}
|
||||
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
@@ -60,7 +60,7 @@ struct fake_segment_manager
|
||||
|
||||
static void *allocate_aligned(std::size_t nbytes, std::size_t alignment)
|
||||
{
|
||||
void *ret = boost_cont_memalign(nbytes, alignment);
|
||||
void *ret = dlmalloc_memalign(nbytes, alignment);
|
||||
if(!ret)
|
||||
boost::container::throw_bad_alloc();
|
||||
return ret;
|
||||
@@ -68,7 +68,7 @@ struct fake_segment_manager
|
||||
|
||||
static void *allocate(std::size_t nbytes)
|
||||
{
|
||||
void *ret = boost_cont_malloc(nbytes);
|
||||
void *ret = dlmalloc_malloc(nbytes);
|
||||
if(!ret)
|
||||
boost::container::throw_bad_alloc();
|
||||
return ret;
|
||||
|
||||
@@ -0,0 +1,191 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// (C) Copyright Ion Gaztanaga 2015-2015. 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_POOL_RESOURCE_HPP
|
||||
#define BOOST_CONTAINER_POOL_RESOURCE_HPP
|
||||
|
||||
#if defined (_MSC_VER)
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/container/detail/config_begin.hpp>
|
||||
#include <boost/container/detail/workaround.hpp>
|
||||
#include <boost/container/pmr/memory_resource.hpp>
|
||||
#include <boost/container/detail/block_list.hpp>
|
||||
#include <boost/container/pmr/pool_options.hpp>
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
namespace boost {
|
||||
namespace container {
|
||||
namespace pmr {
|
||||
|
||||
#if !defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
|
||||
class pool_data_t;
|
||||
|
||||
static const std::size_t pool_options_minimum_max_blocks_per_chunk = 1u;
|
||||
static const std::size_t pool_options_default_max_blocks_per_chunk = 32u;
|
||||
static const std::size_t pool_options_minimum_largest_required_pool_block =
|
||||
memory_resource::max_align > 2*sizeof(void*) ? memory_resource::max_align : 2*sizeof(void*);
|
||||
static const std::size_t pool_options_default_largest_required_pool_block =
|
||||
pool_options_minimum_largest_required_pool_block > 4096u
|
||||
? pool_options_minimum_largest_required_pool_block : 4096u;
|
||||
|
||||
#endif //BOOST_CONTAINER_DOXYGEN_INVOKED
|
||||
|
||||
class pool_resource
|
||||
{
|
||||
typedef block_list_base<> block_list_base_t;
|
||||
|
||||
pool_options m_options;
|
||||
memory_resource& m_upstream;
|
||||
block_list_base_t m_oversized_list;
|
||||
pool_data_t *m_pool_data;
|
||||
std::size_t m_pool_count;
|
||||
|
||||
static void priv_limit_option(std::size_t &val, std::size_t min, std::size_t max);
|
||||
static std::size_t priv_pool_index(std::size_t block_size);
|
||||
static std::size_t priv_pool_block(std::size_t index);
|
||||
|
||||
void priv_fix_options();
|
||||
void priv_init_pools();
|
||||
void priv_constructor_body();
|
||||
|
||||
public:
|
||||
|
||||
//! <b>Requires</b>: `upstream` is the address of a valid memory resource.
|
||||
//!
|
||||
//! <b>Effects</b>: Constructs a pool resource object that will obtain memory
|
||||
//! from upstream whenever the pool resource is unable to satisfy a memory
|
||||
//! request from its own internal data structures. The resulting object will hold
|
||||
//! a copy of upstream, but will not own the resource to which upstream points.
|
||||
//! [ Note: The intention is that calls to upstream->allocate() will be
|
||||
//! substantially fewer than calls to this->allocate() in most cases. - end note
|
||||
//! The behavior of the pooling mechanism is tuned according to the value of
|
||||
//! the opts argument.
|
||||
//!
|
||||
//! <b>Throws</b>: Nothing unless upstream->allocate() throws. It is unspecified if
|
||||
//! or under what conditions this constructor calls upstream->allocate().
|
||||
pool_resource(const pool_options& opts, memory_resource* upstream) BOOST_NOEXCEPT;
|
||||
|
||||
//! <b>Effects</b>: Same as
|
||||
//! `pool_resource(pool_options(), get_default_resource())`.
|
||||
pool_resource() BOOST_NOEXCEPT;
|
||||
|
||||
//! <b>Effects</b>: Same as
|
||||
//! `pool_resource(pool_options(), upstream)`.
|
||||
explicit pool_resource(memory_resource* upstream) BOOST_NOEXCEPT;
|
||||
|
||||
//! <b>Effects</b>: Same as
|
||||
//! `pool_resource(opts, get_default_resource())`.
|
||||
explicit pool_resource(const pool_options& opts) BOOST_NOEXCEPT;
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS) || defined(BOOST_CONTAINER_DOXYGEN_INVOKED)
|
||||
pool_resource(const pool_resource&) = delete;
|
||||
pool_resource operator=(const pool_resource&) = delete;
|
||||
#else
|
||||
private:
|
||||
pool_resource (const pool_resource&);
|
||||
pool_resource operator=(const pool_resource&);
|
||||
public:
|
||||
#endif
|
||||
|
||||
//! <b>Effects</b>: Calls
|
||||
//! `this->release()`.
|
||||
virtual ~pool_resource();
|
||||
|
||||
//! <b>Effects</b>: Calls Calls `upstream_resource()->deallocate()` as necessary
|
||||
//! to release all allocated memory. [ Note: memory is released back to
|
||||
//! `upstream_resource()` even if deallocate has not been called for some
|
||||
//! of the allocated blocks. - end note ]
|
||||
void release();
|
||||
|
||||
//! <b>Returns</b>: The value of the upstream argument provided to the
|
||||
//! constructor of this object.
|
||||
memory_resource* upstream_resource() const;
|
||||
|
||||
//! <b>Returns</b>: The options that control the pooling behavior of this resource.
|
||||
//! The values in the returned struct may differ from those supplied to the pool
|
||||
//! resource constructor in that values of zero will be replaced with
|
||||
//! implementation-defined defaults and sizes may be rounded to unspecified granularity.
|
||||
pool_options options() const;
|
||||
|
||||
public: //public so that [un]synchronized_pool_resource can use them
|
||||
|
||||
//! <b>Returns</b>: A pointer to allocated storage with a size of at least `bytes`.
|
||||
//! The size and alignment of the allocated memory shall meet the requirements for
|
||||
//! a class derived from `memory_resource`.
|
||||
//!
|
||||
//! <b>Effects</b>: If the pool selected for a block of size bytes is unable to
|
||||
//! satisfy the memory request from its own internal data structures, it will call
|
||||
//! `upstream_resource()->allocate()` to obtain more memory. If `bytes` is larger
|
||||
//! than that which the largest pool can handle, then memory will be allocated
|
||||
//! using `upstream_resource()->allocate()`.
|
||||
//!
|
||||
//! <b>Throws</b>: Nothing unless `upstream_resource()->allocate()` throws.
|
||||
virtual void* do_allocate(std::size_t bytes, std::size_t alignment);
|
||||
|
||||
//! <b>Effects</b>: Return the memory at p to the pool. It is unspecified if or under
|
||||
//! what circumstances this operation will result in a call to
|
||||
//! `upstream_resource()->deallocate()`.
|
||||
//!
|
||||
//! <b>Throws</b>: Nothing.
|
||||
virtual void do_deallocate(void* p, std::size_t bytes, std::size_t alignment);
|
||||
|
||||
//! <b>Returns</b>:
|
||||
//! `this == dynamic_cast<const pool_resource*>(&other)`.
|
||||
virtual bool do_is_equal(const memory_resource& other) const BOOST_NOEXCEPT;
|
||||
|
||||
//Non-standard observers
|
||||
public:
|
||||
//! <b>Returns</b>: The number of pools that will be used in the pool resource.
|
||||
//!
|
||||
//! <b>Note</b>: Non-standard extension.
|
||||
std::size_t pool_count() const;
|
||||
|
||||
//! <b>Returns</b>: The index of the pool that will be used to serve the allocation of `bytes`.
|
||||
//! from the pool specified by `pool_index`. Returns `pool_count()` if `bytes` is bigger
|
||||
//! than `options().largest_required_pool_block` (no pool will be used to serve this).
|
||||
//!
|
||||
//! <b>Note</b>: Non-standard extension.
|
||||
std::size_t pool_index(std::size_t bytes) const;
|
||||
|
||||
//! <b>Requires</b>: `pool_idx < pool_index()`
|
||||
//!
|
||||
//! <b>Returns</b>: The number blocks that will be allocated in the next chunk
|
||||
//! from the pool specified by `pool_idx`.
|
||||
//!
|
||||
//! <b>Note</b>: Non-standard extension.
|
||||
std::size_t pool_next_blocks_per_chunk(std::size_t pool_idx) const;
|
||||
|
||||
//! <b>Requires</b>: `pool_idx < pool_index()`
|
||||
//!
|
||||
//! <b>Returns</b>: The number of bytes of the block that the specified `pool_idx` pool manages.
|
||||
//!
|
||||
//! <b>Note</b>: Non-standard extension.
|
||||
std::size_t pool_block(std::size_t pool_idx) const;
|
||||
|
||||
//! <b>Requires</b>: `pool_idx < pool_index()`
|
||||
//!
|
||||
//! <b>Returns</b>: The number of blocks that the specified `pool_idx` pool has cached
|
||||
//! and will be served without calling the upstream_allocator.
|
||||
//!
|
||||
//! <b>Note</b>: Non-standard extension.
|
||||
std::size_t pool_cached_blocks(std::size_t pool_idx) const;
|
||||
};
|
||||
|
||||
} //namespace pmr {
|
||||
} //namespace container {
|
||||
} //namespace boost {
|
||||
|
||||
#include <boost/container/detail/config_end.hpp>
|
||||
|
||||
#endif //BOOST_CONTAINER_POOL_RESOURCE_HPP
|
||||
@@ -30,6 +30,8 @@ namespace boost {
|
||||
namespace container {
|
||||
namespace container_detail {
|
||||
|
||||
using ::boost::move_detail::enable_if;
|
||||
using ::boost::move_detail::enable_if_and;
|
||||
using ::boost::move_detail::is_same;
|
||||
using ::boost::move_detail::is_different;
|
||||
using ::boost::move_detail::is_pointer;
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
# pragma once
|
||||
#endif
|
||||
|
||||
#include <boost/container/detail/config_begin.hpp>
|
||||
|
||||
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)\
|
||||
&& !defined(BOOST_INTERPROCESS_DISABLE_VARIADIC_TMPL)
|
||||
#define BOOST_CONTAINER_PERFECT_FORWARDING
|
||||
@@ -59,6 +57,23 @@
|
||||
#define BOOST_CONTAINER_DOCIGN(T) T
|
||||
#define BOOST_CONTAINER_DOCONLY(T)
|
||||
|
||||
#include <boost/container/detail/config_end.hpp>
|
||||
/*
|
||||
we need to import/export our code only if the user has specifically
|
||||
asked for it by defining either BOOST_ALL_DYN_LINK if they want all boost
|
||||
libraries to be dynamically linked, or BOOST_CONTAINER_DYN_LINK
|
||||
if they want just this one to be dynamically liked:
|
||||
*/
|
||||
#if defined(BOOST_ALL_DYN_LINK) || defined(BOOST_CONTAINER_DYN_LINK)
|
||||
|
||||
/* export if this is our own source, otherwise import: */
|
||||
#ifdef BOOST_CONTAINER_SOURCE
|
||||
# define BOOST_CONTAINER_DECL BOOST_SYMBOL_EXPORT
|
||||
#else
|
||||
# define BOOST_CONTAINER_DECL BOOST_SYMBOL_IMPORT
|
||||
|
||||
#endif /* BOOST_CONTAINER_SOURCE */
|
||||
#else
|
||||
#define BOOST_CONTAINER_DECL
|
||||
#endif /* DYN_LINK */
|
||||
|
||||
#endif //#ifndef BOOST_CONTAINER_DETAIL_WORKAROUND_HPP
|
||||
Reference in new issue
Block a user