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
2015-09-07 19:16:46 +02:00
parent 77100c0bfc
commit 33d2f0f7af
110 changed files with 10143 additions and 1160 deletions

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> >();