Optimizing C++ Singleton Performance: Best Practices and Implementation Guidance
By
jandeboevrie
A good honest bake. Not flashy, but you'll finish the whole bagel.
Summary
This article focuses on optimizing C++ singleton implementations for performance, using a display manager example from the Linux world (like GDM or LightDM). The author builds on a previous post about correct singleton implementation and now adds performance considerations, providing guidance on choosing the best implementation approach for specific use cases.
Key quotes
· 3 pulledIn my January post, I focused on implementing a singleton correctly. This time I want to add performance into the mix and show you the best way to implement your singleton... or give you guidance to pick your best way.
I'm using a display manager as an example, like GDM, LightDM, or others in the Linux world.
Let me quickly go through the various parts. In A, you see the data type Resolution which illustrates two resolutions; you can imagine the rest. Next in B, you find the DisplayManager implementation.
You might also wanna read
C++26's std::is_within_lifetime: Checking Object Lifetime During Constant Evaluation
The article explains C++26's new std::is_within_lifetime function, which checks whether a pointer points to an object within its lifetime du
Implementing an Efficient uint128 Type in Modern C++ for x64 Architecture
This article provides a practical guide to implementing an efficient 128-bit unsigned integer (uint128) type in modern C++. The author focus
C++ Uses Destructors Instead of try...finally for Cleanup Code
The article explains how C++ handles cleanup code differently from other programming languages that have try...finally constructs. While lan
Bjarne Stroustrup on Safe C++: RAII vs Manual Resource Management
The article discusses Bjarne Stroustrup's presentation on Safe C++ programming, focusing on resource management pitfalls in C code and the R
C++20 Coroutines Tutorial: Practical Guide to Asynchronous Programming
This article is a comprehensive tutorial on C++20 coroutines, written by an experienced C++ developer with 25 years of event-driven programm
Compact C++ String Formatting Library Implementation in 65 Lines
A technical article presenting a compact string formatting library implementation in C++ that uses only 65 lines of code. The library was de
