diff --git a/src/GC/lib/heap.cpp b/src/GC/lib/heap.cpp index 4d40550..3389f4b 100644 --- a/src/GC/lib/heap.cpp +++ b/src/GC/lib/heap.cpp @@ -380,11 +380,14 @@ namespace GC std::vector filtered; size_t i = 0; // filtered.push_back(heap->m_freed_chunks.at(i++)); - filtered.push_back(Heap::get_at(heap->m_freed_chunks, i++)); + // filtered.push_back(Heap::get_at(heap->m_freed_chunks, i++)); + auto prev = Heap::get_at(heap->m_freed_chunks, i++); + prev->marked = true; + filtered.push_back(prev); cout << filtered.back()->start << endl; for (; i < heap->m_freed_chunks.size(); i++) { - auto prev = filtered.back(); + prev = filtered.back(); // auto next = heap->m_freed_chunks.at(i); auto next = Heap::get_at(heap->m_freed_chunks, i); auto p_start = (uintptr_t)(prev->start); @@ -392,10 +395,25 @@ namespace GC auto n_start = (uintptr_t)(next->start); if (n_start >= (p_start + p_size)) { + next->marked = true; filtered.push_back(next); } } heap->m_freed_chunks.swap(filtered); + + bool profiler_enabled = heap->profiler_enabled(); + // after swap m_freed_chunks contains still available chunks + // and filtered contains all the chunks, so delete unused chunks + for (Chunk *chunk : filtered) + { + // if chunk was filtered away, delete it + if (!chunk->marked) + { + if (profiler_enabled) + Profiler::record(ChunkFreed, chunk); + delete chunk; + } + } } // ----- ONLY DEBUGGING ----------------------------------------------------------------------- diff --git a/src/GC/todo.md b/src/GC/todo.md index 3fd98c6..30e439b 100644 --- a/src/GC/todo.md +++ b/src/GC/todo.md @@ -6,9 +6,6 @@ Goal for next week (24/2): - Write more complex tests ## GC TODO: -- Skriva klart profiler - - fixa abs_path i create_file_stream -- delete chunk i free_overlap - Kolla linking med Valter/Victor - Fixa en a-fil/static lib till Samuel - Kolla vektor vs list complexity @@ -16,11 +13,4 @@ Goal for next week (24/2): då är alla efter varandra i minnet. ## Tests TODO -- Write complex datastructures for tests with larger programs - -## Profiler grejer -1. [x] Kolla existerande events -2. [x] Nya events för init, dispose i heap.cpp -3. [x] Skriv om try_recycle för att returnera en chunk -4. [x] Copy constructor för chunks (reused chunks) -5. [x] Nya events för try_recycle \ No newline at end of file +- Write complex datastructures for tests with larger programs \ No newline at end of file