Goal for next week
This commit is contained in:
parent
afd5463310
commit
f42ea42273
4 changed files with 51 additions and 17 deletions
|
|
@ -0,0 +1,15 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "include/allocator.hpp"
|
||||||
|
|
||||||
|
namespace GC {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -23,20 +23,27 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
~Heap() {
|
~Heap() {
|
||||||
|
for (auto *alloc : h_allocs)
|
||||||
|
delete alloc;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getHeapSize() {
|
size_t getHeapSize() {
|
||||||
return heap_size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// helt onödig
|
||||||
Allocator *getAllocator(size_t size) {
|
Allocator *getAllocator(size_t size) {
|
||||||
for (auto *alloc : h_allocs) {
|
for (auto *alloc : h_allocs) {
|
||||||
if (alloc->getSize() >= size)
|
if (alloc->getSize() >= size)
|
||||||
return alloc;
|
return alloc;
|
||||||
}
|
}
|
||||||
std::cout << "Object too big" << std::endl;
|
// std::cout << "Object too big" << std::endl;
|
||||||
assert(false);
|
assert(false && "TODO: Object too big");
|
||||||
|
}
|
||||||
|
|
||||||
|
void *alloc(size_t size) {
|
||||||
|
auto allocator = getAllocator(size);
|
||||||
|
return allocator->alloc();
|
||||||
}
|
}
|
||||||
|
|
||||||
void collect();
|
void collect();
|
||||||
|
|
@ -55,7 +62,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
char _heap[HEAP_SIZE] = {0};
|
char _heap[HEAP_SIZE] = {0};
|
||||||
size_t heap_size = 0;
|
size_t size = 0;
|
||||||
std::vector<Allocator *> h_allocs;
|
std::vector<Allocator *> h_allocs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,22 @@
|
||||||
|
|
||||||
class HeapObj {
|
class HeapObj {
|
||||||
public:
|
public:
|
||||||
HeapObj(size_t size_) {
|
HeapObj(void *start_, size_t size_) {
|
||||||
|
start = start_;
|
||||||
size = size_;
|
size = size_;
|
||||||
}
|
}
|
||||||
|
|
||||||
~HeapObj() { }
|
~HeapObj() { }
|
||||||
|
|
||||||
|
void *getAddr() { return start; }
|
||||||
|
|
||||||
|
size_t getSize() { return size; }
|
||||||
|
|
||||||
|
bool isMarked() { return marked; }
|
||||||
|
void mark() { marked = true; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void *start = 0;
|
||||||
size_t size { 0 };
|
size_t size { 0 };
|
||||||
bool marked { false };
|
bool marked { false };
|
||||||
};
|
};
|
||||||
|
|
@ -1,5 +1,14 @@
|
||||||
# Garbage collection
|
# Garbage collection
|
||||||
|
|
||||||
|
## Project
|
||||||
|
|
||||||
|
Goal for next week (17/2):
|
||||||
|
- Functioning garbage collector
|
||||||
|
- Test it with valgrind
|
||||||
|
|
||||||
|
TODO:
|
||||||
|
- Merge to main branch
|
||||||
|
|
||||||
## Algorithm
|
## Algorithm
|
||||||
|
|
||||||
Potential algorithms:
|
Potential algorithms:
|
||||||
|
|
@ -20,15 +29,9 @@ Potential algorithms:
|
||||||
- Holds all memory
|
- Holds all memory
|
||||||
- Resizeable array?
|
- Resizeable array?
|
||||||
- Singleton instance
|
- Singleton instance
|
||||||
|
- exposes alloc
|
||||||
|
|
||||||
- Allocator class
|
- Heap chunks
|
||||||
- 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
|
- size
|
||||||
- location
|
- addr
|
||||||
- marked bit
|
- marked bit
|
||||||
Loading…
Add table
Add a link
Reference in a new issue