项目作者: unveres

项目描述 :
Garbage collection for C
高级语言: C
项目地址: git://github.com/unveres/ezgc.git
创建时间: 2018-05-28T05:58:01Z
项目社区:https://github.com/unveres/ezgc

开源协议:ISC License

下载


ezgc

Ezechiel’s Garbage Collector for C

Minimalistic library providing garbage collection utilities written in C (supports ANSI C and newer standards as well). It’s very simple, featuring allocation functions analogical to those which exist in libc (gcmalloc, gcrealloc, gccalloc, gcfree). Example of use:

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ezgc.h>
  4. void foo()
  5. {
  6. puts("bar");
  7. }
  8. int main()
  9. {
  10. void **str,
  11. **str2;
  12. str = gcmalloc(sizeof(char) * 64); // reference count: 1
  13. str2 = NULL;
  14. gcatfree(str, foo);
  15. strcpy(*str, "Hello World!");
  16. gclink(&str2, str); // reference count: 2
  17. printf("%s\n", (char*)*str);
  18. printf("%s\n\n", (char*)*str2);
  19. gclink(&str, NULL); // reference count: 1
  20. printf("%s\n", (char*)*str2);
  21. gclink(&str2, NULL); // deallocation and calling foo
  22. return 0;
  23. }

Remember to link “libezgc.a” after compiling your project. ;)

How to install

Just download the binary release tarball and unpack it to the root directory.
That’s it.