Fixed bugs on freeing chunks and stack-scanning

Co-authored-by: ValterMiari <ValterMiari@users.noreply.github.com>
This commit is contained in:
Victor Olin 2023-02-22 18:30:15 +01:00
parent 1ccf3dac6b
commit bdca6ffc85
7 changed files with 53 additions and 53 deletions

View file

@ -63,26 +63,23 @@ void test_some_types() {
}
int main() {
//gc->init();
//gc->check_init();
auto stack_start = reinterpret_cast<uintptr_t *>(__builtin_frame_address(0));
std::cout << "Stack start from main:\t" << stack_start << std::endl;
// This is allocated outside of the scope of the GC, thus garbage
for (int i = 0; i < 10; i++) {
gc->alloc(sizeof(int));
// char *c = static_cast<char *>(gc->alloc(sizeof(char))); // 0x0 | 0x0
// int *i = static_cast<int *>(gc->alloc(sizeof(int))); // 0x1-0x4 | 0x4-0x8
// char *c2 = static_cast<char *>(gc->alloc(sizeof(char)));// 0x5 | 0x9-0x
// long *l = static_cast<long *>(gc->alloc(sizeof(long))); // 0x6-0xd | 0x
// This is allocated outside of the scope of the GC (if gc->init() isn't called), thus garbage
long *longs[21];
std::cout << "Pointer to ints:\t" << longs << std::endl;
for (int i = 0; i < 21; i++) {
longs[i] = static_cast<long *>(gc->alloc(sizeof(long)));
}
/* int depth = 10;
Node* nodes[depth];
Node *last_node = static_cast<Node *>(gc->alloc(sizeof(Node)));
last_node->id = depth;
last_node->child = nullptr;
nodes[0] = last_node;
for (int i = 1; i < depth; i++) {
Node *node = static_cast<Node *>(gc->alloc(sizeof(Node)));
node->id = depth-i;
node->child = nodes[i-1];
nodes[i] = node;
} */
//test_chain(10, false);
//test_some_types();
gc->collect(MARK | SWEEP | FREE); // free misses some chunks
gc->print_contents();
return 0;