-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
50 lines (41 loc) · 1.14 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include "gc.h"
void test_gc()
{
printf("\n=== Starting GC Test ===\n");
// Test 1: Basic allocation and collection
printf("\nTest 1: Basic allocation and collection\n");
int *will_survive = gc_alloc(sizeof(int));
if (!will_survive)
{
printf("Failed to allocate will_survive\n");
return;
}
*will_survive = 4;
printf("Allocated will_survive with value %d at %p\n", *will_survive, (void *)will_survive);
// Create some garbage with different sizes to test coalescing
printf("Creating garbage allocations...\n");
for (int i = 0; i < 20; i++)
{
int *temp = gc_alloc(sizeof(int) * (i + 1)); // Varying sizes
printf("WILL SURVIVE: %d\n", *will_survive);
if (temp)
*temp = i;
}
printf("Before GC: will_survive = %d\n", *will_survive);
print_lists();
gc();
printf("After GC: will_survive = %d\n", *will_survive);
print_lists();
printf("=== GC Test Completed ===\n\n");
gc_destroy();
}
int main()
{
test_gc();
return 0;
}