From 7a8573270a84f59fc11dee264ebb825bd1f085bc Mon Sep 17 00:00:00 2001 From: Brett Date: Wed, 6 Mar 2024 23:23:03 -0500 Subject: [PATCH] allocator fun --- libs/BLT | 2 +- tests/src/tests2.cpp | 39 ++++++++++++++++++++++++--------------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/libs/BLT b/libs/BLT index be4a61c..06892a3 160000 --- a/libs/BLT +++ b/libs/BLT @@ -1 +1 @@ -Subproject commit be4a61cc8040ffc1f86bd582a7de5d67397cdb16 +Subproject commit 06892a3418b8340701a57393e725dc5379305897 diff --git a/tests/src/tests2.cpp b/tests/src/tests2.cpp index 0f20eca..118ff8c 100644 --- a/tests/src/tests2.cpp +++ b/tests/src/tests2.cpp @@ -98,20 +98,21 @@ namespace fb std::array(type_t::END)> arg_c = {2, 2, 2, 2, 0}; + template class tree1 { public: - blt::bump_allocator alloc{sizeof(node_t) * 8192}; + ALLOC alloc{sizeof(node_t) * 8192}; private: struct node_t { - blt::bump_allocator& alloc; + ALLOC& alloc; std::array children{nullptr}; double value = 0; blt::i32 argc; type_t type; - explicit node_t(type_t type, blt::bump_allocator& alloc): + explicit node_t(type_t type, ALLOC& alloc): alloc(alloc), argc(arg_c[static_cast(type)]), type(type) { if (type == type_t::VALUE) @@ -183,7 +184,7 @@ namespace fb void create(blt::u64 size) { - root = alloc.emplace(random_type(), alloc); + root = alloc.template emplace(random_type(), alloc); std::stack> stack; stack.emplace(root, 0); while (!stack.empty()) @@ -198,14 +199,14 @@ namespace fb { if (depth >= size) { - node->children[i] = alloc.emplace(type_t::VALUE, alloc); + node->children[i] = alloc.template emplace(type_t::VALUE, alloc); //BLT_INFO("Skipping due to size, value %lf", node->children[i]->value); continue; } if (choice()) - node->children[i] = alloc.emplace(random_type(), alloc); + node->children[i] = alloc.template emplace(random_type(), alloc); else - node->children[i] = alloc.emplace(random_type_sub(), alloc); + node->children[i] = alloc.template emplace(random_type_sub(), alloc); //BLT_INFO("child %p to %p has type generated %ld with argc %d, value %lf", node->children[i], node, // static_cast(node->children[i]->type), node->children[i]->argc, node->children[i]->value); if (depth < size) @@ -224,28 +225,36 @@ namespace fb ~tree1() { + BLT_START_INTERVAL("Tree Destruction", blt::type_string() + ": Single Class Tree"); alloc.destroy(root); alloc.deallocate(root); + BLT_END_INTERVAL("Tree Destruction", blt::type_string() + ": Single Class Tree"); } }; - void funny() + template + void bump() { - blt::bump_allocator2 alloc; - constexpr auto size = 512; constexpr auto tree_size = 17; engine.reset(); - tree1 love[size]; + tree1 love[size]; for (auto& i : love) i.create(tree_size); - BLT_START_INTERVAL("Tree Evaluation", "Single Class Bump Allocated Tree"); + BLT_START_INTERVAL("Tree Evaluation", blt::type_string() + ": Single Class Tree"); for (auto& i : love) - { blt::black_box(i.evaluate()); - } - BLT_END_INTERVAL("Tree Evaluation", "Single Class Bump Allocated Tree"); + BLT_END_INTERVAL("Tree Evaluation", blt::type_string() + ": Single Class Tree"); + } + + void funny() + { + bump>(); + bump>(); + bump>(); + BLT_PRINT_PROFILE("Tree Evaluation"); + BLT_PRINT_PROFILE("Tree Destruction"); } void execute()