Switched back to vectors
This commit is contained in:
parent
87f5d7fe74
commit
aae3a5ff78
3 changed files with 8 additions and 9 deletions
|
|
@ -42,7 +42,7 @@ namespace GC {
|
||||||
return m_instance;
|
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();
|
auto iter = list.begin();
|
||||||
if (!n)
|
if (!n)
|
||||||
return *iter;
|
return *iter;
|
||||||
|
|
@ -55,9 +55,9 @@ namespace GC {
|
||||||
uintptr_t *try_recycle_chunks(size_t size);
|
uintptr_t *try_recycle_chunks(size_t size);
|
||||||
void free(Heap* heap);
|
void free(Heap* heap);
|
||||||
void free_overlap(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_line(Chunk *chunk);
|
||||||
void print_worklist(std::list<Chunk *> list);
|
void print_worklist(std::vector<Chunk *> list);
|
||||||
|
|
||||||
inline static Heap *m_instance = nullptr;
|
inline static Heap *m_instance = nullptr;
|
||||||
const char *m_heap;
|
const char *m_heap;
|
||||||
|
|
@ -66,8 +66,8 @@ namespace GC {
|
||||||
uintptr_t *m_stack_top = nullptr;
|
uintptr_t *m_stack_top = nullptr;
|
||||||
|
|
||||||
// maybe change to std::list
|
// maybe change to std::list
|
||||||
std::list<Chunk *> m_allocated_chunks;
|
std::vector<Chunk *> m_allocated_chunks;
|
||||||
std::list<Chunk *> m_freed_chunks;
|
std::vector<Chunk *> m_freed_chunks;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -168,7 +168,7 @@ namespace GC {
|
||||||
* @param end Pointer to the end of the stack frame.
|
* @param end Pointer to the end of the stack frame.
|
||||||
* @param worklist The currently allocated chunks, which haven't been marked.
|
* @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;
|
int counter = 0;
|
||||||
// To find adresses thats in the worklist
|
// To find adresses thats in the worklist
|
||||||
for (; start < end; start++) {
|
for (; start < end; start++) {
|
||||||
|
|
@ -273,7 +273,7 @@ namespace GC {
|
||||||
* larger chunks.
|
* larger chunks.
|
||||||
*/
|
*/
|
||||||
void Heap::free_overlap(Heap *heap) {
|
void Heap::free_overlap(Heap *heap) {
|
||||||
std::list<Chunk *> filtered;
|
std::vector<Chunk *> filtered;
|
||||||
size_t i = 0;
|
size_t i = 0;
|
||||||
// filtered.push_back(heap->m_freed_chunks.at(i++));
|
// filtered.push_back(heap->m_freed_chunks.at(i++));
|
||||||
filtered.push_back(getAt(heap->m_freed_chunks, 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;
|
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) {
|
for (auto cp : list) {
|
||||||
cout << "Chunk at:\t" << cp->start << "\nSize:\t\t" << cp->size << endl;
|
cout << "Chunk at:\t" << cp->start << "\nSize:\t\t" << cp->size << endl;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ Goal for next week (24/2):
|
||||||
- Write more complex tests
|
- Write more complex tests
|
||||||
|
|
||||||
## GC TODO:
|
## GC TODO:
|
||||||
- Merge to main branch
|
|
||||||
- Double check m_heap_size functionality and when a collection is triggered
|
- Double check m_heap_size functionality and when a collection is triggered
|
||||||
- Kolla vektor vs list complexity
|
- Kolla vektor vs list complexity
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue