Why C ++ can't have an extra transparent garbage collector

There is a question related to this, but this one is slightly different, and I am not happy with any of the answers to the corresponding question :)

I am going to ask this question negatively, arguing that it is impossible to have an optional transparent garbage collector for C ++ and hope that someone will prove that I'm wrong. Yes, Stroustrup tried this and repeatedly failed, not because of technical problems, but because of compatibility issues. Performance is not a problem here.

The reason C ++ will never have such a collector is because an optional program that runs without a collector must implement all the necessary memory management manually. Adding a collector can then give some performance benefits, but it’s not clear what they cost (yes, the collector can be faster).

What you cannot get is automatic memory management, which is the main reason collectors desire. You will receive this with a compulsory collection (not necessarily sacrificing RAII or other things if you choose to perform proper manual control). Mandatory collector with additional manual memory management can be used.

Unfortunately, the only way to get a required collector creates incompatibility with earlier versions of C ++ that do not use a collector: in other words, we must define a new language if we want to automatically manage transparent memory.

So, I argue: C ++ will never have garbage collection, since it is locked in historical development, which requires upward compatibility: a mandatory collection with additional manual memory management is viable, but there is no transparent additional garbage collection.

Prove that I'm wrong by showing a flexible, optional, transparent garbage collection model!

EDIT:

Ooh .. I think I have an answer. Can someone quote the Standard where it requires programs to delete allocated heaps of objects?

: , , - , . , ++ 1x.

undefined: , , . : , , .

+3
6

, , !

: ++/CLI.

++ , ++ , ; RAII. , RAII , RAII . , , - RAII, , .

, , , "" - - ++/CLI, : " , ", - .

+11

, , downvotes. .

, - " ++ GC?" " , . , . , . , , - hokus pokus. GC, . GC , ".

, . # .NET GC. CLR ++. , , .

, , , # , ++ , ++ #.

, ...

+9

, . , GC - std::gc_pointer<T>?

GC. , ( ++ 0x) - , . std:: gc_new? std:: make_shared.

++ 0x , , .

+1

" Lamborghini ?" ;)

++ # . , .

+1

, (, , : ( delete , ) , ), , .

GC . "" GC'ed- , - , GC , .

++ . GC , , , / .

, , , ++ " , ".

An alternative used by the existing GC is to implement a conservative GC, which may not return all memory, as it must guess whether the word is a pointer or not, and if in doubt, it has to be pessimistic.

+1
source

Can I prove that you are mistaken by giving examples of optional transparent garbage collectors for C ++?

There is also a good discussion on the Boehm website that should be necessary to read such questions.

0
source

Source: https://habr.com/ru/post/1782670/


All Articles