【发布时间】:2015-07-13 04:43:54
【问题描述】:
我在 C 中遇到了这个问题,我必须实现一个垃圾收集器。我坚持这样一个事实,即我被赋予了 4 个功能来完成,并且不确定它们如何相互连接。我不知道该怎么办。这是我目前所拥有的:
void mygc() {
//int **max = (int **) 0xbfffffffUL; // the address of the top of the stack
unsigned long stack_bottom;
int **max = (int **) GC_init(); // get the address of the bottom of the stack
int* q;
int **p = &q; // the address of the bottom of the stack
while (p < max) {
//printf("0. p: %u, *p: %u max: %u\n",p,*p,max);
mark(*p);
p++;
}
//utilize sweep and coalesce (coalesce function already written)
}
void mark(int *p) {
int i;
int *ptr;
//code here
}
void sweep(int *ptr) {
// code here
}
int *isPtr(int *p) {
//return the pointer or NULL
int *ptr = start;
//code here
}
【问题讨论】:
-
变量;不使用“stack_bottom”。这会引发编译器警告。建议启用所有编译器警告,重新编译,修复警告,重新发布代码。鉴于发布的代码,还有其他几个编译器警告。请发布编译/链接的代码,以便我们调试问题
-
如果您包含对每个功能预期完成的内容的描述,也许会有所帮助。
-
顺便说一句,如果你还没有#t,你可能想看看boehm collector
标签: c garbage-collection mark-and-sweep