views:

55

answers:

1

I am writing a statically compiled language and i would like to support garbage collection. before designing it i would like to know how i should i deduce when the GC should run?

Should it be after every 16mb allocate interval? (checking after enough rises or just before it allocates 16+mb). Is there a case to check ealier so loops can reuse the same memory to be efficient? etc

+1  A: 

The best time for an GC to run is propably "when the program has some time left". For example, if you have a run loop and no event is queued it might be a good time to run the GC. And then maybe also if the GC allocator notices that it would need to ask the OS for more memory. I think it also depends on the GC design, e.g. It's possible to design a GC that runs in its own thread and doesn't interrupt the program vs. the usual "stop the world" GCs.

Question is also, do you want to implement a GC just for learning ? Or do you just want a GC ? In the later case I suggest you look into the Boehm GC.

DarkDust
"when the program has some time left" sounds like sleep and a mutex lock. I like that you mentioned Boehm GC. I currently output C++ code and adding this seems trivial. I was asking for both learning and just wanted a GC. I didnt want to write one or cared how good it was but i do want to know how it works. I can see the some time left going wrong if theres tons of little allocations all over the place which would take long to sort through.
acidzombie24