CppCon 2019: Pete Isensee “Destructor Case Studies: Best Practices for Safe and Efficient Teardown”

preview_player
Показать описание



Destructors are arguably the most important feature of C++. By allowing deterministic resource management, destructors enable proper cleanup at the right time. However, implementing destructors correctly can be challenging even for experienced developers, and ensuring destructors are optimized can be critical in high performance code. In this presentation, we’ll examine a series of real world destructors, including some from the C++ Standard Library, to generate a list of best practices.

Pete Isensee
Facebook Reality Labs
Engineering Manager
Bellevue, Washington

Pete Isensee has programmed video games, shipped three generations of Xbox consoles at Microsoft, created VR experiences at HBO, published dozens of technical articles, and taught C++ tips & tricks to game developers worldwide. Pete is currently a software engineering manager at Facebook Reality Labs (previously Oculus Research), helping unlock the potential of virtual and augmented reality.


*-----*
*-----*
Рекомендации по теме
Комментарии
Автор

That bit about exit() - super helpful. Now I'll be on the lookout for any [[noreturn]]-like functions.

DimiterStanev
Автор

You should have noted that function-try-block in destructor does not what one expects. It was the most surprising thing I have learned about destructors - function-try-block actually re-throws exceptions even if the programmer puts an empty catch(...) block so it is basically a no-op. One should always put the try/catch(...) inside the { } in destructors, otherwise if you also declare destructor noexcept it will call std::terminate on any exception caught

pazdziochowaty
Автор

This is a great talk! Exactly the information I’ve looking for about destructors.

MrFedX
Автор

INVALID_HANDLE_VALUE might be a valid value for some handles. For example CreateEvent and CreateIoCompletionPort return NULL if they fail. INVALID_HANDLE_VALUE is mainly returned by functions carried over from 16-bit Windows if they fail.

IsaacClancy
Автор

8:57 : if you call exit, isn’t all the memory used by the process returned to the os?

trondenver
Автор

The version of Uhura that uses std::unique_ptr should use std::make_unique otherwise last I knew it could still leak memory.

IsaacClancy
Автор

9:10, nothing is destroyed if an atexit() is called?!
10:50, I didn't know that noexcept was default.

MrAbrazildo