From e745593d94a1351bb8df9ef7055c309e80aaea3d Mon Sep 17 00:00:00 2001 From: Victor Olin Date: Thu, 23 Mar 2023 13:32:24 +0100 Subject: [PATCH] Testing vector indexing --- src/GC/lib/heap.cpp | 9 ++++++--- src/GC/tests/h_test.cpp | 16 ++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/GC/lib/heap.cpp b/src/GC/lib/heap.cpp index e581cbf..f92088c 100644 --- a/src/GC/lib/heap.cpp +++ b/src/GC/lib/heap.cpp @@ -130,7 +130,8 @@ namespace GC // Check if there are any freed chunks large enough for current request for (size_t i = 0; i < heap.m_freed_chunks.size(); i++) { - auto chunk = Heap::get_at(heap.m_freed_chunks, i); + // auto chunk = Heap::get_at(heap.m_freed_chunks, i); + auto chunk = heap.m_freed_chunks[i]; auto iter = heap.m_freed_chunks.begin(); advance(iter, i); if (chunk->m_size > size) @@ -373,14 +374,16 @@ namespace GC { std::vector filtered; size_t i = 0; - auto prev = Heap::get_at(heap.m_freed_chunks, i++); + // auto prev = Heap::get_at(heap.m_freed_chunks, i++); + auto prev = heap.m_freed_chunks[i++]; prev->m_marked = true; filtered.push_back(prev); cout << filtered.back()->m_start << endl; for (; i < heap.m_freed_chunks.size(); i++) { prev = filtered.back(); - auto next = Heap::get_at(heap.m_freed_chunks, i); + // auto next = Heap::get_at(heap.m_freed_chunks, i); + auto next = heap.m_freed_chunks[i]; auto p_start = (uintptr_t)(prev->m_start); auto p_size = (uintptr_t)(prev->m_size); auto n_start = (uintptr_t)(next->m_start); diff --git a/src/GC/tests/h_test.cpp b/src/GC/tests/h_test.cpp index 28f6387..2755149 100644 --- a/src/GC/tests/h_test.cpp +++ b/src/GC/tests/h_test.cpp @@ -67,9 +67,9 @@ void test_some_types() { int main() { GC::Heap::init(); - GC::Heap *gc = GC::Heap::debug_the(); - gc->set_profiler(true); - gc->check_init(); + GC::Heap &gc = GC::Heap::the(); + gc.set_profiler(true); + gc.check_init(); auto stack_start = reinterpret_cast(__builtin_frame_address(0)); std::cout << "Stack start from main:\t" << stack_start << std::endl; @@ -86,7 +86,7 @@ int main() { longs++; } */ - Node *root = static_cast(gc->alloc(sizeof(Node))); + Node *root = static_cast(gc.alloc(sizeof(Node))); root = test_chain(3, false); Node *root_child = root->child; std::cout << "Adress of root:\t" << &root << std::endl; @@ -95,9 +95,9 @@ int main() { std::cout << "Root child, child:\t" << root_child->child << std::endl; - gc->collect(GC::COLLECT_ALL); - gc->print_contents(); - - gc->dispose(); + gc.collect(GC::COLLECT_ALL); + gc.print_contents(); + + gc.dispose(); return 0; } \ No newline at end of file