What Does a Trash Collector Do?

The Bem Garbage Collector is a conservative garbage collector for computer applications in the C / C ++ language. It can be applied to many projects developed through C \ C ++.

The Boehm-Demers-Weiser garbage collector , also known as the Boehm GC , is a conservative garbage collector for computer applications in the C / C ++ language. It can be applied to many projects developed through C / C ++, and it is also suitable for other implementations. Various programming languages of the environment, including
Garbage Collection (GC) is an automatic method in computer science.
The garbage collector acts on unmodified C programs. As long as you simply replace malloc calls with GC_malloc and realloc with GC_realloc calls, you do not need to use the free function. The following code shows how to replace traditional malloc and free with Boehm.
  #include "gc.h" #include <assert.h> #include <stdio.h> int main () {int i; GC_INIT (); for (i = 0; i <10000000; I) {int ** p = (int **) GC_MALLOC (sizeof (int *)); int * q = (int *) GC_MALLOC_ATOMIC (sizeof (int)); assert (* p == 0); * p = (int *) GC_REALLOC (q , 2 * sizeof (int)); if (i% 100000 == 0) printf ("Heap size =% d \ n", GC_get_heap_size ());} return 0;} 

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?