namespace boost { namespace container { namespace test {
-static const int NumIt = 200;
+static const std::size_t NumIt = 200;
enum deallocation_type { DirectDeallocation, InverseDeallocation, MixedDeallocation, EndDeallocationType };
std::vector<void*> buffers;
//std::size_t free_memory = a.get_free_memory();
- for(int i = 0; i != NumIt; ++i){
+ for(std::size_t i = 0; i != NumIt; ++i){
void *ptr = dlmalloc_malloc(i);
if(!ptr)
break;
switch(t){
case DirectDeallocation:
{
- for(int j = 0, max = (int)buffers.size()
+ for(std::size_t j = 0, max = buffers.size()
;j < max
;++j){
dlmalloc_free(buffers[j]);
break;
case InverseDeallocation:
{
- for(int j = (int)buffers.size()
+ for(std::size_t j = buffers.size()
;j--
;){
dlmalloc_free(buffers[j]);
break;
case MixedDeallocation:
{
- for(int j = 0, max = (int)buffers.size()
+ for(std::size_t j = 0, max = buffers.size()
;j < max
;++j){
- int pos = (j%4)*((int)buffers.size())/4;
+ std::size_t pos = (j%4)*(buffers.size())/4;
dlmalloc_free(buffers[pos]);
- buffers.erase(buffers.begin()+pos);
+ buffers.erase(buffers.begin()+(std::ptrdiff_t)pos);
}
}
break;
std::vector<void*> buffers;
//Allocate buffers with extra memory
- for(int i = 0; i != NumIt; ++i){
- void *ptr = dlmalloc_malloc(i*2);
+ for(std::size_t i = 0; i != NumIt; ++i){
+ void *ptr = dlmalloc_malloc(i*2u);
if(!ptr)
break;
buffers.push_back(ptr);
}
//Now shrink to half
- for(int i = 0, max = (int)buffers.size()
+ for(std::size_t i = 0, max = buffers.size()
;i < max
; ++i){
std::size_t try_received_size = 0;
}
//Deallocate it in non sequential order
- for(int j = 0, max = (int)buffers.size()
+ for(std::size_t j = 0, max = buffers.size()
;j < max
;++j){
- int pos = (j%4)*((int)buffers.size())/4;
+ std::size_t pos = (j%4u)*(buffers.size())/4u;
dlmalloc_free(buffers[pos]);
- buffers.erase(buffers.begin()+pos);
+ buffers.erase(buffers.begin()+(std::ptrdiff_t)pos);
}
dlmalloc_malloc_check();
return 0 != dlmalloc_all_deallocated();//a.all_memory_deallocated() && a.check_sanity();
std::vector<void*> buffers;
//Allocate buffers with extra memory
- for(int i = 0; i != NumIt; ++i){
+ for(std::size_t i = 0; i != NumIt; ++i){
void *ptr = dlmalloc_malloc(i);
if(!ptr)
break;
}
//Now try to expand to the double of the size
- for(int i = 0, max = (int)buffers.size()
+ for(std::size_t i = 0, max = buffers.size()
;i < max
;++i){
std::size_t received_size = 0;
}
//Deallocate it in non sequential order
- for(int j = 0, max = (int)buffers.size()
+ for(std::size_t j = 0, max = buffers.size()
;j < max
;++j){
- int pos = (j%4)*((int)buffers.size())/4;
+ std::size_t pos = (j%4u)*(buffers.size())/4u;
dlmalloc_free(buffers[pos]);
- buffers.erase(buffers.begin()+pos);
+ buffers.erase(buffers.begin()+(std::ptrdiff_t)pos);
}
dlmalloc_malloc_check();
return 0 != dlmalloc_all_deallocated();//a.all_memory_deallocated() && a.check_sanity();
std::vector<bool> size_reduced;
//Allocate buffers wand store received sizes
- for(int i = 0; i != NumIt; ++i){
+ for(std::size_t i = 0; i != NumIt; ++i){
std::size_t received_size = 0;
void *ptr = dlmalloc_allocation_command
- (BOOST_CONTAINER_ALLOCATE_NEW, 1, i, i*2, &received_size, 0).first;
+ (BOOST_CONTAINER_ALLOCATE_NEW, 1u, i, i*2u, &received_size, 0).first;
if(!ptr){
ptr = dlmalloc_allocation_command
- ( BOOST_CONTAINER_ALLOCATE_NEW, 1, 1, i*2, &received_size, 0).first;
+ ( BOOST_CONTAINER_ALLOCATE_NEW, 1u, 1u, i*2, &received_size, 0).first;
if(!ptr)
break;
}
}
//Now shrink to half
- for(int i = 0, max = (int)buffers.size()
+ for(std::size_t i = 0, max = buffers.size()
; i < max
; ++i){
std::size_t received_size = 0;
}
//Now try to expand to the original size
- for(int i = 0, max = (int)buffers.size()
+ for(std::size_t i = 0, max = buffers.size()
;i < max
;++i){
if(!size_reduced[i]) continue;
}
//Deallocate it in non sequential order
- for(int j = 0, max = (int)buffers.size()
+ for(std::size_t j = 0, max = buffers.size()
;j < max
;++j){
- int pos = (j%4)*((int)buffers.size())/4;
+ std::size_t pos = (j%4u)*(buffers.size())/4u;
dlmalloc_free(buffers[pos]);
- buffers.erase(buffers.begin()+pos);
+ buffers.erase(buffers.begin()+(std::ptrdiff_t)pos);
}
return 0 != dlmalloc_all_deallocated();//a.all_memory_deallocated() && a.check_sanity();
std::vector<void*> buffers;
//Allocate buffers with extra memory
- for(int i = 0; i != NumIt; ++i){
+ for(std::size_t i = 0; i != NumIt; ++i){
void *ptr = dlmalloc_malloc(i);
if(!ptr)
break;
//Now deallocate the half of the blocks
//so expand maybe can merge new free blocks
- for(int i = 0, max = (int)buffers.size()
+ for(std::size_t i = 0, max = buffers.size()
;i < max
;++i){
if(i%2){
}
//Now try to expand to the double of the size
- for(int i = 0, max = (int)buffers.size()
+ for(std::size_t i = 0, max = buffers.size()
;i < max
;++i){
//
,buffers.end());
//Deallocate it in non sequential order
- for(int j = 0, max = (int)buffers.size()
+ for(std::size_t j = 0, max = buffers.size()
;j < max
;++j){
- int pos = (j%4)*((int)buffers.size())/4;
+ std::size_t pos = (j%4u)*(buffers.size())/4u;
dlmalloc_free(buffers[pos]);
- buffers.erase(buffers.begin()+pos);
+ buffers.erase(buffers.begin()+(std::ptrdiff_t)pos);
}
dlmalloc_malloc_check();
return 0 != dlmalloc_all_deallocated();//a.all_memory_deallocated() && a.check_sanity();
{
dlmalloc_malloc_check();
//We will repeat this test for different sized elements
- for(int sizeof_object = 1; sizeof_object < 20; ++sizeof_object){
+ for(std::size_t sizeof_object = 1; sizeof_object < 20; ++sizeof_object){
std::vector<void*> buffers;
//Allocate buffers with extra memory
- for(int i = 0; i != NumIt; ++i){
+ for(std::size_t i = 0; i != NumIt; ++i){
void *ptr = dlmalloc_malloc(i*sizeof_object);
if(!ptr)
break;
//Now deallocate all except the latest
//Now try to expand to the double of the size
- for(int i = 0, max = (int)buffers.size() - 1
+ for(std::size_t i = 0, max = buffers.size() - 1
;i < max
;++i){
dlmalloc_free(buffers[i]);
//Now allocate with reuse
std::size_t received_size = 0;
- for(int i = 0; i != NumIt; ++i){
- std::size_t min_size = (received_size/sizeof_object + 1)*sizeof_object;
- std::size_t prf_size = (received_size/sizeof_object + (i+1)*2)*sizeof_object;
+ for(std::size_t i = 0; i != NumIt; ++i){
+ std::size_t min_size = (received_size/sizeof_object + 1u)*sizeof_object;
+ std::size_t prf_size = (received_size/sizeof_object + (i+1u)*2u)*sizeof_object;
dlmalloc_command_ret_t ret = dlmalloc_allocation_command
( BOOST_CONTAINER_EXPAND_BWD, sizeof_object, min_size
, prf_size, &received_size, (char*)ptr);
dlmalloc_malloc_check();
//Allocate aligned buffers in a loop
//and then deallocate it
- for(unsigned int i = 1; i != (1 << (sizeof(int)/2)); i <<= 1){
- for(unsigned int j = 1; j != 512; j <<= 1){
+ for(std::size_t i = 1u; i != (1u << (sizeof(int)/2u)); i <<= 1u){
+ for(std::size_t j = 1u; j != 512u; j <<= 1){
void *ptr = dlmalloc_memalign(i-1, j);
if(!ptr){
return false;
//Allocate aligned buffers in a loop
//and then deallocate it
bool continue_loop = true;
- unsigned int MaxAlign = 4096;
- unsigned int MaxSize = 4096;
- for(unsigned i = 1; i < MaxSize; i <<= 1){
- for(unsigned int j = 1; j < MaxAlign; j <<= 1){
- for(int k = 0; k != NumIt; ++k){
+ std::size_t MaxAlign = 4096;
+ std::size_t MaxSize = 4096;
+ for(std::size_t i = 1; i < MaxSize; i <<= 1){
+ for(std::size_t j = 1; j < MaxAlign; j <<= 1){
+ for(std::size_t k = 0; k != NumIt; ++k){
void *ptr = dlmalloc_memalign(i-1, j);
buffers.push_back(ptr);
if(!ptr){
return false;
}
//Deallocate all
- for(int k = (int)buffers.size(); k--;){
+ for(std::size_t k = buffers.size(); k--;){
dlmalloc_free(buffers[k]);
}
buffers.clear();
std::vector<void*> buffers2;
//Allocate buffers with extra memory
- for(int i = 0; i != NumIt; ++i){
+ for(std::size_t i = 0; i != NumIt; ++i){
void *ptr = dlmalloc_malloc(i);
if(!ptr)
break;
//Now deallocate the half of the blocks
//so expand maybe can merge new free blocks
- for(int i = 0, max = (int)buffers2.size()
+ for(std::size_t i = 0, max = buffers2.size()
;i < max
;++i){
if(i%2){
//return false;
std::vector<void*> buffers;
- for(int i = 0; i != NumIt/10; ++i){
+ for(std::size_t i = 0; i != NumIt/10; ++i){
dlmalloc_memchain chain;
BOOST_CONTAINER_MEMCHAIN_INIT(&chain);
dlmalloc_multialloc_nodes((i+1)*2, i+1, BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, &chain);
switch(t){
case DirectDeallocation:
{
- for(int j = 0, max = (int)buffers.size()
+ for(std::size_t j = 0, max = buffers.size()
;j < max
;++j){
dlmalloc_free(buffers[j]);
break;
case InverseDeallocation:
{
- for(int j = (int)buffers.size()
+ for(std::size_t j = buffers.size()
;j--
;){
dlmalloc_free(buffers[j]);
break;
case MixedDeallocation:
{
- for(int j = 0, max = (int)buffers.size()
+ for(std::size_t j = 0, max = buffers.size()
;j < max
;++j){
- int pos = (j%4)*((int)buffers.size())/4;
+ std::size_t pos = (j%4u)*(buffers.size())/4u;
dlmalloc_free(buffers[pos]);
- buffers.erase(buffers.begin()+pos);
+ buffers.erase(buffers.begin()+(std::ptrdiff_t)pos);
}
}
break;
//Deallocate the rest of the blocks
//Deallocate it in non sequential order
- for(int j = 0, max = (int)buffers2.size()
+ for(std::size_t j = 0, max = buffers2.size()
;j < max
;++j){
- int pos = (j%4)*((int)buffers2.size())/4;
+ std::size_t pos = (j%4u)*(buffers2.size())/4u;
dlmalloc_free(buffers2[pos]);
- buffers2.erase(buffers2.begin()+pos);
+ buffers2.erase(buffers2.begin()+(std::ptrdiff_t)pos);
}
//bool ok = free_memory == a.get_free_memory() &&
std::vector<void*> buffers2;
//Allocate buffers with extra memory
- for(int i = 0; i != NumIt; ++i){
+ for(std::size_t i = 0; i != NumIt; ++i){
void *ptr = dlmalloc_malloc(i);
if(!ptr)
break;
//Now deallocate the half of the blocks
//so expand maybe can merge new free blocks
- for(int i = 0, max = (int)buffers2.size()
+ for(std::size_t i = 0, max = buffers2.size()
;i < max
;++i){
if(i%2){
}
std::vector<void*> buffers;
- for(int i = 0; i != NumIt; ++i){
+ for(std::size_t i = 0; i != NumIt; ++i){
dlmalloc_memchain chain;
BOOST_CONTAINER_MEMCHAIN_INIT(&chain);
dlmalloc_multialloc_arrays(ArraySize, requested_sizes, 1, BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, &chain);
switch(t){
case DirectDeallocation:
{
- for(int j = 0, max = (int)buffers.size()
+ for(std::size_t j = 0, max = buffers.size()
;j < max
;++j){
dlmalloc_free(buffers[j]);
break;
case InverseDeallocation:
{
- for(int j = (int)buffers.size()
+ for(std::size_t j = buffers.size()
;j--
;){
dlmalloc_free(buffers[j]);
break;
case MixedDeallocation:
{
- for(int j = 0, max = (int)buffers.size()
+ for(std::size_t j = 0, max = buffers.size()
;j < max
;++j){
- int pos = (j%4)*((int)buffers.size())/4;
+ std::size_t pos = (j%4)*(buffers.size())/4;
dlmalloc_free(buffers[pos]);
- buffers.erase(buffers.begin()+pos);
+ buffers.erase(buffers.begin()+(std::ptrdiff_t)pos);
}
}
break;
//Deallocate the rest of the blocks
//Deallocate it in non sequential order
- for(int j = 0, max = (int)buffers2.size()
+ for(std::size_t j = 0, max = buffers2.size()
;j < max
;++j){
- int pos = (j%4)*((int)buffers2.size())/4;
+ std::size_t pos = (j%4u)*(buffers2.size())/4u;
dlmalloc_free(buffers2[pos]);
- buffers2.erase(buffers2.begin()+pos);
+ buffers2.erase(buffers2.begin()+(std::ptrdiff_t)pos);
}
//bool ok = free_memory == a.get_free_memory() &&
requested_sizes[i] = 4*i;
}
- for(int i = 0; i != NumIt; ++i){
+ for(std::size_t i = 0; i != NumIt; ++i){
dlmalloc_memchain chain;
BOOST_CONTAINER_MEMCHAIN_INIT(&chain);
dlmalloc_multialloc_arrays(ArraySize, requested_sizes, 1, BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, &chain);
return false;
buffers.push_back(chain);
}
- for(int i = 0; i != NumIt; ++i){
+ for(std::size_t i = 0; i != NumIt; ++i){
dlmalloc_multidealloc(&buffers[i]);
}
buffers.clear();
if(!dlmalloc_all_deallocated())
return false;
- for(int i = 0; i != NumIt; ++i){
+ for(std::size_t i = 0; i != NumIt; ++i){
dlmalloc_memchain chain;
BOOST_CONTAINER_MEMCHAIN_INIT(&chain);
dlmalloc_multialloc_nodes(ArraySize, i*4+1, BOOST_CONTAINER_DL_MULTIALLOC_DEFAULT_CONTIGUOUS, &chain);
return false;
buffers.push_back(chain);
}
- for(int i = 0; i != NumIt; ++i){
+ for(std::size_t i = 0; i != NumIt; ++i){
dlmalloc_multidealloc(&buffers[i]);
}
buffers.clear();