Switched back to vectors

This commit is contained in:
Victor Olin 2023-02-24 20:41:59 +01:00
parent 87f5d7fe74
commit aae3a5ff78
3 changed files with 8 additions and 9 deletions

View file

@ -42,7 +42,7 @@ namespace GC {
return m_instance;
}
static inline Chunk *getAt(std::list<Chunk *> list, size_t n) {
static inline Chunk *getAt(std::vector<Chunk *> 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<Chunk *> worklist);
void mark(uintptr_t *start, const uintptr_t *end, std::vector<Chunk *> worklist);
void print_line(Chunk *chunk);
void print_worklist(std::list<Chunk *> list);
void print_worklist(std::vector<Chunk *> 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<Chunk *> m_allocated_chunks;
std::list<Chunk *> m_freed_chunks;
std::vector<Chunk *> m_allocated_chunks;
std::vector<Chunk *> m_freed_chunks;
public:

View file

@ -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<Chunk*> worklist) {
void Heap::mark(uintptr_t *start, const uintptr_t *end, vector<Chunk*> 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<Chunk *> filtered;
std::vector<Chunk *> 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<Chunk *> list) {
void Heap::print_worklist(std::vector<Chunk *> list) {
for (auto cp : list) {
cout << "Chunk at:\t" << cp->start << "\nSize:\t\t" << cp->size << endl;
}

View file

@ -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