Goal for next week

This commit is contained in:
Victor Olin 2023-02-10 13:47:09 +01:00
parent e52c38f5f7
commit 7d91cf871a
4 changed files with 51 additions and 17 deletions

View file

@ -0,0 +1,15 @@
#pragma once
#include <assert.h>
#include <iostream>
#include <stdlib.h>
#include <vector>
#include "include/allocator.hpp"
namespace GC {
}

View file

@ -23,20 +23,27 @@ public:
}
~Heap() {
for (auto *alloc : h_allocs)
delete alloc;
}
size_t getHeapSize() {
return heap_size;
return size;
}
// helt onödig
Allocator *getAllocator(size_t size) {
for (auto *alloc : h_allocs) {
if (alloc->getSize() >= size)
return alloc;
}
std::cout << "Object too big" << std::endl;
assert(false);
// std::cout << "Object too big" << std::endl;
assert(false && "TODO: Object too big");
}
void *alloc(size_t size) {
auto allocator = getAllocator(size);
return allocator->alloc();
}
void collect();
@ -55,7 +62,7 @@ private:
}
char _heap[HEAP_SIZE] = {0};
size_t heap_size = 0;
size_t size = 0;
std::vector<Allocator *> h_allocs;
};

View file

@ -4,13 +4,22 @@
class HeapObj {
public:
HeapObj(size_t size_) {
HeapObj(void *start_, size_t size_) {
start = start_;
size = size_;
}
~HeapObj() { }
void *getAddr() { return start; }
size_t getSize() { return size; }
bool isMarked() { return marked; }
void mark() { marked = true; }
private:
void *start = 0;
size_t size { 0 };
bool marked { false };
};

View file

@ -1,5 +1,14 @@
# Garbage collection
## Project
Goal for next week (17/2):
- Functioning garbage collector
- Test it with valgrind
TODO:
- Merge to main branch
## Algorithm
Potential algorithms:
@ -20,15 +29,9 @@ Potential algorithms:
- Holds all memory
- Resizeable array?
- Singleton instance
- exposes alloc
- Allocator class
- Allocates chunks of memory
- keeps track of chunks that are available and their sizes
- Several instances of allocator class with different sizes?
- HeapObj class
- parent of all heap objects
- contains metadata
- size
- location
- marked bit
- Heap chunks
- size
- addr
- marked bit