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:
Ion Gaztañaga committed 2015-09-07 19:16:46 +02:00
1 parent 77100c0bfc
commit 33d2f0f7af
110 files changed
+10143 -1160

No files matched your search

+7 -7
View File
@@ -129,7 +129,7 @@ void list_test_template(std::size_t num_iterations, std::size_t num_elements, bo
{
typedef typename Allocator::template rebind<MyInt>::other IntAllocator;
nanosecond_type tinsert, terase;
boost_cont_malloc_stats_t insert_stats, erase_stats;
bc::dlmalloc_malloc_stats_t insert_stats, erase_stats;
std::size_t insert_inuse, erase_inuse;
const size_t sizeof_node = 2*sizeof(void*)+sizeof(int);
@@ -145,8 +145,8 @@ void list_test_template(std::size_t num_iterations, std::size_t num_elements, bo
timer.stop();
tinsert = timer.elapsed().wall;
insert_inuse = boost_cont_in_use_memory();
insert_stats = boost_cont_malloc_stats();
insert_inuse = bc::dlmalloc_in_use_memory();
insert_stats = bc::dlmalloc_malloc_stats();
/*
iterator_t it(l.begin());
iterator_t last(--l.end());
@@ -175,8 +175,8 @@ void list_test_template(std::size_t num_iterations, std::size_t num_elements, bo
}
timer.stop();
terase = timer.elapsed().wall;
erase_inuse = boost_cont_in_use_memory();
erase_stats = boost_cont_malloc_stats();
erase_inuse = bc::dlmalloc_in_use_memory();
erase_stats = bc::dlmalloc_malloc_stats();
}
@@ -214,7 +214,7 @@ void list_test_template(std::size_t num_iterations, std::size_t num_elements, bo
<< " / "
<< (float)insert_inuse/(1024*1024) << "(" << (float(insert_inuse)/(num_iterations*num_elements*sizeof_node)*100.0)-100.0 << "%)"
<< std::endl
<< " system MB/inuse bytes after: " << (float)erase_stats.system_bytes/(1024*1024) << '\t' << boost_cont_in_use_memory()
<< " system MB/inuse bytes after: " << (float)erase_stats.system_bytes/(1024*1024) << '\t' << bc::dlmalloc_in_use_memory()
<< std::endl << std::endl;
}
@@ -243,7 +243,7 @@ void list_test_template(std::size_t num_iterations, std::size_t num_elements, bo
boost::container::container_detail::singleton_default
<shared_adaptive_pool_plus_align_only_t>::instance().deallocate_free_blocks();
//Release dlmalloc memory
boost_cont_trim(0);
bc::dlmalloc_trim(0);
}
void print_header()
+17 -15
View File
@@ -12,7 +12,7 @@
#pragma warning (disable : 4512)
#endif
#include <boost/container/detail/alloc_lib_auto_link.hpp>
#include <boost/container/detail/dlmalloc.hpp>
#define BOOST_INTERPROCESS_VECTOR_ALLOC_STATS
@@ -24,6 +24,8 @@ using boost::timer::cpu_timer;
using boost::timer::cpu_times;
using boost::timer::nanosecond_type;
using namespace boost::container;
template <class POD>
void allocation_timing_test(unsigned int num_iterations, unsigned int num_elements)
{
@@ -50,23 +52,23 @@ void allocation_timing_test(unsigned int num_iterations, unsigned int num_elemen
for(unsigned int r = 0; r != num_iterations; ++r){
void *first_mem = 0;
if(m_mode != BOOST_CONTAINER_EXPAND_FWD)
first_mem = boost_cont_malloc(sizeof(POD)*num_elements*3/2);
void *addr = boost_cont_malloc(1*sizeof(POD));
first_mem = dlmalloc_malloc(sizeof(POD)*num_elements*3/2);
void *addr = dlmalloc_malloc(1*sizeof(POD));
if(m_mode == BOOST_CONTAINER_EXPAND_FWD)
first_mem = boost_cont_malloc(sizeof(POD)*num_elements*3/2);
capacity = boost_cont_size(addr)/sizeof(POD);
boost_cont_free(first_mem);
first_mem = dlmalloc_malloc(sizeof(POD)*num_elements*3/2);
capacity = dlmalloc_size(addr)/sizeof(POD);
dlmalloc_free(first_mem);
++numalloc;
try{
boost_cont_command_ret_t ret;
dlmalloc_command_ret_t ret;
for(size_t e = capacity + 1; e < num_elements; ++e){
size_t received_size;
size_t min = (capacity+1)*sizeof(POD);
size_t max = (capacity*3/2)*sizeof(POD);
if(min > max)
max = min;
ret = boost_cont_allocation_command
ret = dlmalloc_allocation_command
( m_mode, sizeof(POD)
, min, max, &received_size, addr);
if(!ret.first){
@@ -79,7 +81,7 @@ void allocation_timing_test(unsigned int num_iterations, unsigned int num_elemen
std::cout << "m_mode != BOOST_CONTAINER_ALLOCATE_NEW!" << std::endl;
return;
}
boost_cont_free(addr);
dlmalloc_free(addr);
addr = ret.first;
++numalloc;
}
@@ -95,16 +97,16 @@ void allocation_timing_test(unsigned int num_iterations, unsigned int num_elemen
addr = ret.first;
e = capacity + 1;
}
boost_cont_free(addr);
dlmalloc_free(addr);
}
catch(...){
boost_cont_free(addr);
dlmalloc_free(addr);
throw;
}
}
assert( boost_cont_allocated_memory() == 0);
if(boost_cont_allocated_memory()!= 0){
assert( dlmalloc_allocated_memory() == 0);
if(dlmalloc_allocated_memory()!= 0){
std::cout << "Memory leak!" << std::endl;
return;
}
@@ -122,7 +124,7 @@ void allocation_timing_test(unsigned int num_iterations, unsigned int num_elemen
<< (float(numalloc) + float(numexpand))/num_iterations
<< "(" << float(numalloc)/num_iterations << "/" << float(numexpand)/num_iterations << ")"
<< std::endl << std::endl;
boost_cont_trim(0);
dlmalloc_trim(0);
}
}
@@ -169,7 +171,7 @@ int allocation_loop()
int main()
{
boost_cont_mallopt( (-3)//M_MMAP_THRESHOLD
dlmalloc_mallopt( (-3)//M_MMAP_THRESHOLD
, 100*10000000);
//allocation_loop<char_holder<4> >();
//allocation_loop<char_holder<6> >();
+5 -5
View File
@@ -109,9 +109,9 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements
v.reset_alloc_stats();
void *first_mem = 0;
try{
first_mem = boost_cont_malloc(sizeof(MyInt)*num_elements*3/2);
first_mem = bc::dlmalloc_malloc(sizeof(MyInt)*num_elements*3/2);
v.push_back(MyInt(0));
boost_cont_free(first_mem);
bc::dlmalloc_free(first_mem);
for(unsigned int e = 0; e != num_elements; ++e){
v.push_back(MyInt(e));
@@ -121,12 +121,12 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements
capacity = static_cast<unsigned int>(v.capacity());
}
catch(...){
boost_cont_free(first_mem);
bc::dlmalloc_free(first_mem);
throw;
}
}
assert(boost_cont_allocated_memory() == 0);
assert(bc::dlmalloc_allocated_memory() == 0);
timer.stop();
nanosecond_type nseconds = timer.elapsed().wall;
@@ -165,7 +165,7 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements
<< " ----------------------------------- "
<< std::endl;
}
boost_cont_trim(0);
bc::dlmalloc_trim(0);
}
int main(int argc, const char *argv[])
+1 -1
View File
@@ -223,7 +223,7 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements
<< "(" << float(numalloc)/num_iterations << "/" << float(numexpand)/num_iterations << ")"
<< std::endl << std::endl;
}
boost_cont_trim(0);
bc::dlmalloc_trim(0);
}
void print_header()
+1 -1
View File
@@ -126,7 +126,7 @@ void vector_test_template(unsigned int num_iterations, unsigned int num_elements
<< float(nseconds)/(num_iterations*num_elements)
<< std::endl << std::endl;
}
boost_cont_trim(0);
bc::dlmalloc_trim(0);
}
int main(int argc, const char *argv[])
+2 -2
View File
@@ -174,8 +174,8 @@ void stable_vector_test_template(unsigned int num_iterations, unsigned int num_e
<< " (" << (float(top_capacity)/float(num_iterations*num_elements) - 1)*100 << " %)"*/
<< std::endl << std::endl;
}
assert(boost_cont_all_deallocated());
boost_cont_trim(0);
assert(bc::dlmalloc_all_deallocated());
bc::dlmalloc_trim(0);
}
void print_header()