Well I've mostly finished my "Simple-Garbage-Collector" library or SGC for short. But since I am a hobbyist and did this on my free time I feel like I have missed something important.
Also I hope this is the right place to post this.
About the GC
Well the garbage collector uses the Mark-Sweep algorithm and has been written in C++. Also sadly it's a Stop-the-world but I might add support for an Incremental approach. The collection must be manually activated by a function call to the collector. SGC also support to have several collectors running at the same time, though the SGC namespace creates a default collector for your convenience.
Memory allocation
For the developer using SGC that is only using the default collector will only have to inherit his classes from the SGC::Tracked class which overloads the new and delete operators to call on a collector instance to allocate the memory. Behind the scenes the collector is managing a list of memory pools with a set size starting at 1 MB and doubling the size if it gets filled up. These memory pools are the ones actually handling the allocation and deallocation of the memory. The collector is only in charge of tracking any memory.
Global namespace
I had a problem when it came to the global namespace. I don't know how to acquire a pointer to the start of the global namespace or if possible the end of the namespace either. So I improvised and created a function called MakeEternal which can be called on any tracked object. This function will mark this object to only be collected when the collector itself is destroyed.
KISS (Keep-It-Simple-Stupid)
I want to point out also that I went for the KISS-principle while designing this library. I wanted the collector to be so simple as possible and more or less work without the need for the developer to do anything. The only part that goes against this is that the user needs to call Collect him self.
Example Of Use
#include <SGC/SGC.hpp>
SGC::Tracked * t3;
void func() {
SGC::Tracked * t1 = new SGC::Tracked();
SGC::Tracked * t2 = new SGC::Tracked();
t3 = new SGC::Tracked();
t3->MakeEternal();
SGC::Tracked t4;
}
int main() {
func();
SGC::DefaultCollector()->Collect();
return 0;
}
The objects collected are t1, t2. t3 won't be collected until the end of the program. t4 is never collected since it's not created by the new-operator but it will be destroyed when the function returns.
The Question
Just to be clear, I repeat the question here. Do I seem to miss anything that is expected to be in a garbage collector? Also it would be nice with normal feedback. For a better view here's the documentation: Simple-Garbage-Collector


Sign In
Create Account


Back to top









