3 ms·
> Why bother running through a destructor chain ... The Gold linker (written in C++) doesn't ( http://www.airs.com/blog/archives/362 http://www.airs.com/blog/a
by maxlybbert 12y ago
> Why bother running through a destructor chain ...
The Gold linker (written in C++) doesn't ( http://www.airs.com/blog/archives/362 http://www.airs.com/blog/archives/362 ): "[I]n the gold linker I often deliberately omitted destructors, because many of the data structures live for the life the program; in such a case, destructors serve only to slow down program exit."
However, there are some things that you really want to know happened when the process exits for any reason. If possible, you'd probably like your files closed in a way that allows them to be re-opened. That's easy to do with destructors. Destructors: they were always for more than just memory management.
- astrange 12y ago> If possible, you'd probably like your files closed in a way that allows them to be re-opened. That's easy to do with destructors. That doesn't help with data corruption coming from the environment. The power going off on your machine, your external drive, a crash in your process or an external signal all won't give you time to exit. There are libraries worth relying on for this, like SQLite. It's not in C++.
- maxlybbert 12y agoThis is a weird argument: "I just bought a Porsche, and it handles better than any car I've owned!"/"you can't tow things with a Porsche." Anyhow, as you implicitly acknowledge, destructors help with orderly shutdown, even if the shutdown is caused by an error condition. I prefer them to try...finally that other languages rely on. I can live with C#'s IDisposable, but I personally have a better chance of getting my destructors right than implementing IDisposable correctly (remember, in a garbage collected language, you don't have a defined order that things will be destroyed in). But, on the completely different topic of how to do disaster recovery when both your program and the host operating system are shut down in a non-orderly manner: I personally am not aware of any language features in any language that make that easier. However, I know it can be done in C++ (stasis ( http://stasis.io/ http://stasis.io/ ), SQL Server, MySQL/MariaDB, Firebird ( http://firebirdsql.org/ http://firebirdsql.org/ ) and SciDB ( http://www.scidb.org/ http://www.scidb.org/ ) are all implemented in C++, although they aren't all necessarily object oriented C++).