mkirchner / gc

Simple, zero-dependency garbage collection for C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can I mix this library with POSIX malloc family

haifenghuang opened this issue · comments

As the issue title said, Can I have below code?

int main(int argc, char* argv[]) {
    gc = gc_start(gc, &argc);
    ...
    gc_calloc();
    ...
    ptr = malloc();
    free(ptr);
    ...
    gc_stop(gc);
    return 0;
}

@haifenghuang, yes that is possible. Just keep in mind that (a) gc will (obviously) not manage any raw malloc() pointers for you; and (b) pointers to gc_*alloc() memory that reside in memory that was allocated through non-gc means, will not have any impact on mark/sweep (in particular reachability).

That said, I am not sure about your intention behind the call to gc_calloc() in your example; I think you meant to write something like

...
int* ptr = gc_calloc(gc, n, sizeof(int));
...

Please close the issue if this answers your question, thanks!

Thanks a lot!