From aae3a5ff787218c54aa5401c86ccd2961874f0f1 Mon Sep 17 00:00:00 2001 From: Victor Olin Date: Fri, 24 Feb 2023 20:41:59 +0100 Subject: [PATCH] Switched back to vectors --- src/GC/include/heap.hpp | 10 +++++----- src/GC/lib/heap.cpp | 6 +++--- src/GC/todo.md | 1 - 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/GC/include/heap.hpp b/src/GC/include/heap.hpp index c70ee54..2517b4e 100644 --- a/src/GC/include/heap.hpp +++ b/src/GC/include/heap.hpp @@ -42,7 +42,7 @@ namespace GC { return m_instance; } - static inline Chunk *getAt(std::list list, size_t n) { + static inline Chunk *getAt(std::vector list, size_t n) { auto iter = list.begin(); if (!n) return *iter; @@ -55,9 +55,9 @@ namespace GC { uintptr_t *try_recycle_chunks(size_t size); void free(Heap* heap); void free_overlap(Heap *heap); - void mark(uintptr_t *start, const uintptr_t *end, std::list worklist); + void mark(uintptr_t *start, const uintptr_t *end, std::vector worklist); void print_line(Chunk *chunk); - void print_worklist(std::list list); + void print_worklist(std::vector list); inline static Heap *m_instance = nullptr; const char *m_heap; @@ -66,8 +66,8 @@ namespace GC { uintptr_t *m_stack_top = nullptr; // maybe change to std::list - std::list m_allocated_chunks; - std::list m_freed_chunks; + std::vector m_allocated_chunks; + std::vector m_freed_chunks; public: diff --git a/src/GC/lib/heap.cpp b/src/GC/lib/heap.cpp index c17f680..bfd6f26 100644 --- a/src/GC/lib/heap.cpp +++ b/src/GC/lib/heap.cpp @@ -168,7 +168,7 @@ namespace GC { * @param end Pointer to the end of the stack frame. * @param worklist The currently allocated chunks, which haven't been marked. */ - void Heap::mark(uintptr_t *start, const uintptr_t *end, list worklist) { + void Heap::mark(uintptr_t *start, const uintptr_t *end, vector worklist) { int counter = 0; // To find adresses thats in the worklist for (; start < end; start++) { @@ -273,7 +273,7 @@ namespace GC { * larger chunks. */ void Heap::free_overlap(Heap *heap) { - std::list filtered; + std::vector filtered; size_t i = 0; // filtered.push_back(heap->m_freed_chunks.at(i++)); filtered.push_back(getAt(heap->m_freed_chunks, i++)); @@ -384,7 +384,7 @@ namespace GC { cout << "Marked: " << chunk->marked << "\nStart adr: " << chunk->start << "\nSize: " << chunk->size << " B\n" << endl; } - void Heap::print_worklist(std::list list) { + void Heap::print_worklist(std::vector list) { for (auto cp : list) { cout << "Chunk at:\t" << cp->start << "\nSize:\t\t" << cp->size << endl; } diff --git a/src/GC/todo.md b/src/GC/todo.md index f9492da..bf3ee51 100644 --- a/src/GC/todo.md +++ b/src/GC/todo.md @@ -6,7 +6,6 @@ Goal for next week (24/2): - Write more complex tests ## GC TODO: -- Merge to main branch - Double check m_heap_size functionality and when a collection is triggered - Kolla vektor vs list complexity