Any major projects use Boehm GC?
I am curious if any major projects have used Boehm GC? I'm particularly interested in if any gaming projects have used this garbage collector. If not, is Boehm GC bad for gaming projects?
I am impressed by the mere fact that simple code such as this Boehm GC can handle:
#include <stdio.h>
#include <stdlib.h开发者_运维百科>
#include <gc.h>
int main(void)
{
int i;
GC_INIT();
for (i = 0; i < 10000000; ++i)
{
int *p = GC_MALLOC(sizeof(int *));
//int *q = malloc(sizeof(int *));
printf("Heap size = %d\n", GC_get_heap_size());
}
return 0;
}
Are there any caveats to making a game using Boehm GC?
Thanks
The Open Modelica Compiler (OMC) makes use of the Boehm GC. It is a very large application with over 300 000 lines of code and is used both in industry and in research. The garbage collector collects garbage during simulations.
See https://github.com/OpenModelica/OMCompiler/tree/master/SimulationRuntime/c/gc It defines the internal API for the garbage collector and might be a good reference and an interesting read.
However, if you are going to make a game in C++ I would recomend using smart pointers instead. If you really would like the comfort of having a garbage collector and you need to use C or C++ for some reason Boehm is a good option. Otherwise if performance is not critical for the game that you are programming, it might be wise to look at other languages with efficient garbage collectors such as Java or C#.
精彩评论