|
|
@ -120,11 +120,14 @@ struct buddy_test : public test_scaffold { |
|
|
|
gp::repeat(10, [&](){ |
|
|
|
gp::array<char, 4096> store; |
|
|
|
{ |
|
|
|
gp::buddy<gp::dummy_allocator, gp::math::msb<uint64_t>(4096)> bud{&*store.begin(), store.size()}; |
|
|
|
gp::buddy<gp::dummy_allocator, gp::math::msb<uint64_t>(4096)> dum_bud{store.size()}; |
|
|
|
gp::buddy<static_mapper> inner_bud{2048}; |
|
|
|
gp::dummy_allocator dummyall; |
|
|
|
static_assert(gp::math::msb<uint64_t>(8) == 3); |
|
|
|
static_assert(gp::math::msb<uint64_t>(127) == 7); |
|
|
|
static_assert(gp::math::msb<uint64_t>(4096) == 12); |
|
|
|
gp::buddy<gp::math::msb<uint64_t>(4096)> bud{&*store.begin(), store.size()}; |
|
|
|
gp::buddy<gp::math::msb<uint64_t>(4096)> dum_bud{store.size(), dummyall}; |
|
|
|
{ |
|
|
|
gp::buddy<> inner_bud{2048, bud}; |
|
|
|
gp_config::assertion(!dummyall.try_reallocate(nullptr, 0), "reallocation works wut?"); |
|
|
|
gp_config::assertion(!bud.try_reallocate(nullptr, 0), "reallocation works wut?"); |
|
|
|
gp_config::assertion(!inner_bud.try_reallocate(nullptr, 0), "reallocation works wut?"); |
|
|
@ -133,7 +136,10 @@ struct buddy_test : public test_scaffold { |
|
|
|
{ |
|
|
|
void* v = inner_bud.allocate(16); |
|
|
|
gp_config::assertion(!inner_bud.empty(), "allocator should have elements"); |
|
|
|
if(v == nullptr) throw gp::runtime_error("allocation failed"); |
|
|
|
if(v == nullptr) |
|
|
|
{ |
|
|
|
throw gp::runtime_error("allocation failed"); |
|
|
|
} |
|
|
|
ptr_set.insert(v); |
|
|
|
} |
|
|
|
bool wut = ptr_set.count(nullptr)!=0 || ptr_set.size()!=(2048/16); |
|
|
@ -250,7 +256,7 @@ struct buddy_fuzz_test : public test_scaffold { |
|
|
|
virtual int run() { |
|
|
|
int res = 0; |
|
|
|
alignas(8) gp::array<char, 4096> store; |
|
|
|
gp::buddy<gp::dummy_allocator, gp::math::msb<uint64_t>(4096)> bud{&*store.begin(), store.size()}; |
|
|
|
gp::buddy<gp::math::msb<uint64_t>(4096)> bud{&*store.begin(), store.size()}; |
|
|
|
std::vector<void*> ptr_set; |
|
|
|
auto get_random_mem_qt = [&]() -> size_t { |
|
|
|
return 1+rng()%(store.size()-1); |
|
|
@ -342,10 +348,10 @@ struct ring_list_test : public test_scaffold { |
|
|
|
virtual int run() { |
|
|
|
int res = 0; |
|
|
|
alignas(8) gp::array<char, 4096> store; |
|
|
|
using local_allocator = gp::buddy<gp::dummy_allocator, gp::math::msb<uint64_t>(4096)>; |
|
|
|
using local_allocator = gp::buddy<gp::math::msb<uint64_t>(4096)>; |
|
|
|
local_allocator bud{&*store.begin(), store.size()}; |
|
|
|
{ |
|
|
|
using string_ring = gp::ring_list<std::stringp">, local_allocator, false>; |
|
|
|
using string_ring = gp::ring_list<std::string>; |
|
|
|
auto p = new(bud.allocate(sizeof(std::string))) std::string("Hello"); |
|
|
|
auto orig = new(bud.allocate(sizeof(string_ring::node))) string_ring::node(p); |
|
|
|
string_ring ring{orig, bud}; |
|
|
@ -377,12 +383,12 @@ struct aggregator_test : public test_scaffold { |
|
|
|
virtual int run() { |
|
|
|
int res = 0; |
|
|
|
alignas(8) gp::array<char, 4096> store; |
|
|
|
using local_allocator = gp::buddy<gp::dummy_allocator, gp::math::msb<uint64_t>(4096)>; |
|
|
|
using local_allocator = gp::buddy<gp::math::msb<uint64_t>(4096)>; |
|
|
|
local_allocator bud{&*store.begin(), store.size()}; |
|
|
|
alignas(8) gp::array<char, 4096> store2; |
|
|
|
local_allocator bud2{&*store2.begin(), store2.size()}; |
|
|
|
|
|
|
|
gp::aggregator allocator{bud}; |
|
|
|
gp::aggregator allocator(bud); |
|
|
|
allocator.insert(bud2); |
|
|
|
{ |
|
|
|
std::vector<void*> ptr_set; |
|
|
@ -423,28 +429,28 @@ struct aggregator_test : public test_scaffold { |
|
|
|
gp_config::assertion(allocator.deallocate(nullptr) == false, "error, could free an invalid pointer"); |
|
|
|
allocator.deallocate(a); |
|
|
|
{ |
|
|
|
gp::ring_list<intp">, gp::aggregator, false> list{allocator}; |
|
|
|
gp::ring_list<int> list{allocator}; |
|
|
|
list.insert(8); |
|
|
|
list.insert(16); |
|
|
|
list.insert(32); |
|
|
|
} |
|
|
|
{ |
|
|
|
gp::array<char, 256> work_array; |
|
|
|
gp::arena<> alloc_work(work_array.begin().data, work_array.size()); |
|
|
|
gp::ring_list<intp">, gp::arena<>, false> list{alloc_work}; |
|
|
|
gp::arena alloc_work(work_array.begin().data, work_array.size()); |
|
|
|
gp::ring_list<int> list{alloc_work}; |
|
|
|
gp_config::assertion(list.insert(8) == true, "could allocate in list with good enough allocator"); |
|
|
|
gp_config::assertion(list.insert(8) == true, "could allocate in list with good enough allocator"); |
|
|
|
gp_config::assertion(list.insert(8) == true, "could allocate in list with good enough allocator"); |
|
|
|
} |
|
|
|
{ |
|
|
|
gp::array<char, sizeof(int)> once_array; |
|
|
|
gp::arena<> alloc_once(once_array.begin().data, once_array.size()); |
|
|
|
gp::ring_list<intp">, gp::arena<>, false> list{alloc_once}; |
|
|
|
gp::arena alloc_once(once_array.begin().data, once_array.size()); |
|
|
|
gp::ring_list<int> list{alloc_once}; |
|
|
|
gp_config::assertion(list.insert(8) == false, "could allocate in list with insufficient allocator"); |
|
|
|
} |
|
|
|
{ |
|
|
|
gp::arena<> alloc_none(nullptr, 0); |
|
|
|
gp::ring_list<intp">, gp::arena<>, false> list{alloc_none}; |
|
|
|
gp::arena alloc_none(nullptr, 0); |
|
|
|
gp::ring_list<int> list{alloc_none}; |
|
|
|
gp_config::assertion(list.insert(8) == false, "could allocate in list with fake allocator"); |
|
|
|
} |
|
|
|
return res; |
|
|
@ -699,7 +705,7 @@ struct alloc_bench_test : public test_scaffold { |
|
|
|
if(do_bench) { |
|
|
|
auto store = std::make_unique<std::array<char, 1 << 16>>(); |
|
|
|
using buddy_loc = gp::buddy<>; |
|
|
|
using arena_loc = gp::arenao"><>; |
|
|
|
using arena_loc = gp::arena; |
|
|
|
buddy_loc bud{&*store->begin(), store->size()}; |
|
|
|
arena_loc are{&*store->begin(), store->size()}; |
|
|
|
|
|
|
@ -707,13 +713,13 @@ struct alloc_bench_test : public test_scaffold { |
|
|
|
|
|
|
|
for(size_t divider = 2; divider < 32; ++divider) |
|
|
|
{ |
|
|
|
gp::ring_list<intp">, buddy_loc> a{bud}; |
|
|
|
gp::ring_list<intp">, arena_loc> b{are}; |
|
|
|
gp::ring_list<int> a{bud}; |
|
|
|
gp::ring_list<int> b{are}; |
|
|
|
|
|
|
|
std::cout << |
|
|
|
"ARE | " << "INS | " << divider << " | " << |
|
|
|
time_operation([&](){ |
|
|
|
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<intp">, arena_loc>::node)/divider; i++) { |
|
|
|
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<int>::node)/divider; i++) { |
|
|
|
b.insert(i); |
|
|
|
} |
|
|
|
}).count() << std::endl; |
|
|
@ -721,8 +727,8 @@ struct alloc_bench_test : public test_scaffold { |
|
|
|
std::cout << |
|
|
|
"ARE | " << "DEL | " << divider << " | " << |
|
|
|
time_operation([&](){ |
|
|
|
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<intp">, arena_loc>::node)/divider; i++) { |
|
|
|
gp::ring_list<intp">, arena_loc>::explorer e = b.explore(); |
|
|
|
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<int>::node)/divider; i++) { |
|
|
|
gp::ring_list<int>::explorer e = b.explore(); |
|
|
|
b.remove(e); |
|
|
|
} |
|
|
|
}).count() << std::endl; |
|
|
@ -730,7 +736,7 @@ struct alloc_bench_test : public test_scaffold { |
|
|
|
std::cout << |
|
|
|
"BUD | " << "INS | " << divider << " | " << |
|
|
|
time_operation([&](){ |
|
|
|
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<intp">, buddy_loc>::node)/divider; i++) { |
|
|
|
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<int>::node)/divider; i++) { |
|
|
|
a.insert(i); |
|
|
|
} |
|
|
|
}).count() << std::endl; |
|
|
@ -738,22 +744,22 @@ struct alloc_bench_test : public test_scaffold { |
|
|
|
std::cout << |
|
|
|
"BUD | " << "DEL | " << divider << " | " << |
|
|
|
time_operation([&](){ |
|
|
|
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<intp">, buddy_loc>::node)/divider; i++) { |
|
|
|
gp::ring_list<intp">, buddy_loc>::explorer e = a.explore(); |
|
|
|
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<int>::node)/divider; i++) { |
|
|
|
gp::ring_list<int>::explorer e = a.explore(); |
|
|
|
a.remove(e); |
|
|
|
} |
|
|
|
}).count() << std::endl; |
|
|
|
} |
|
|
|
{ |
|
|
|
gp::ring_list<intp">, buddy_loc> a{bud}; |
|
|
|
gp::ring_list<intp">, arena_loc> b{are}; |
|
|
|
gp::ring_list<int> a{bud}; |
|
|
|
gp::ring_list<int> b{are}; |
|
|
|
|
|
|
|
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<intp">, buddy_loc>::node)/2; i++) { |
|
|
|
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<int>::node)/2; i++) { |
|
|
|
a.insert(i); |
|
|
|
} |
|
|
|
|
|
|
|
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<intp">, buddy_loc>::node)/2; i++) { |
|
|
|
gp::ring_list<intp">, buddy_loc>::explorer e = a.explore(); |
|
|
|
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<int>::node)/2; i++) { |
|
|
|
gp::ring_list<int>::explorer e = a.explore(); |
|
|
|
a.remove(++e); |
|
|
|
} |
|
|
|
} |
|
|
|