Overriding C++ new and delete operators to make garbage collector

Started by
21 comments, last by GameDev.net 19 years, 9 months ago
Yes, the compiler automatically calls the constructor and deconstructor no matter how you over-ride new/delete, so no problems making your own.
Advertisement
Quote:Original post by Extrarius
I haven't examined it in great detail, but I'm pretty sure the boehm gc isn't as fast as it could be because it manually scans memory instead of keeping track of everything with smart pointers. Yes, they would be a pain to use in the code, but they could greatly speed up the GC because it wouldn't need to scan anything except the limited class of pointers(I'm guessing there would be many classes of pointers for specific attributes, such as 'top level pointers', 'pointers that are a class member', 'function-local pointers', etc or something like that) it needs to.


But don't you think countless people before who have researched and developed garbage collectors would have thought about doing this if it was so obvious? Big companies like Sun for Java and MS for .NET will have researched garbage collection before picking a method and I'd be gobsmacked if you could better all their work by tinkering around. I'm not saying you shouldn't, but you might find it more rewarding to study previous work instead of reinventing the wheel. Like have you actually tried the Boeh GC? It's very good.
seanw: I dont doubt that it is good, I just think that my priorities are different than theirs. I think all garbage collectors out there are concentrating primarily on making it easy to use with no hastle (and, within that constraint, makign it very fast), while the smart pointer approach I was talking about is annoying because you have to do extra work to use it, but it should be faster. I'm not looking for a GC so that my C++ code can be GC, but so that I can easily use it in C++ to make my scripting language have GC (so certain C++ classes related to the scripting need to be GCed, but I'll still be using manual memory management where appropriate such as classes that need the memory to persist exactly as long as they do where I can use constructor/destructor to handle it properly).

Implementation details always depend on priorities.

-Extrarius

This topic is closed to new replies.

Advertisement