Started testing the GC

Co-authored-by: ValterMiari <ValterMiari@users.noreply.github.com>
This commit is contained in:
Victor Olin 2023-02-15 16:57:11 +01:00
parent f8d761411d
commit c05bf76662
7 changed files with 188 additions and 65 deletions

View file

@ -0,0 +1,29 @@
#include <stdio.h>
#include "heap.hpp"
struct Obj {
int a;
int b;
int c;
};
int main() {
GC::Heap *heap = GC::Heap::the2();
Obj *obj;
for (int i = 0; i < 4; i++) {
obj = static_cast<Obj *>(heap->alloc(sizeof(Obj)));
obj->a = i * i + 1;
obj->b = i * i + 2;
obj->c = i * i + 3;
}
// heap->force_collect();
std::cout << obj->a << ", " << obj->b << ", " << obj->c << std::endl;
//delete heap;
return 0;
}

View file

@ -1,16 +1,23 @@
#include "../include/heap.hpp"
#include "heap.hpp"
GC::Heap gc;
GC::Heap *gc = GC::Heap::the2();
void init() {
gc = GC::Heap::the(); // pointer to the heap
std::vector<int> live_int_vec(100);
std::vector<int> dead_int_vec(100);
gc.alloc(sizeof(live_int_vec));
gc.alloc(sizeof(dead_int_vec));
std::vector<int> live_int_vec{1, 2, 3, 4, 5};
std::vector<int> dead_int_vec(10, 1);
int *a_ptr;
int a = 10;
a_ptr = &a;
auto temp1 = gc->alloc(sizeof(a_ptr));
auto temp2 = gc->alloc(sizeof(live_int_vec));
auto temp3 = gc->alloc(sizeof(dead_int_vec));
a_ptr = nullptr;
}
int main() {
gc.print_contents();
init();
gc->force_collect();
gc->print_contents();
//delete gc;
return 0;
}

30
src/GC/tests/linker.cpp Normal file
View file

@ -0,0 +1,30 @@
#include <stdio.h>
#include "heap.hpp"
struct Obj {
int a;
int b;
int c;
};
int main() {
auto heap = GC::Heap::the2();
std::cout << "heap:\t" << heap << std::endl;
auto obj = static_cast<Obj *>(heap->alloc(sizeof(Obj)));
std::cout << "obj: \t" << obj << std::endl;
obj->a = 3;
obj->b = 4;
obj->c = 5;
std::cout << obj->a << ", " << obj->b << ", " << obj->c << std::endl;
heap->print_contents();
//delete heap;
return 0;
}