Remember to lock around all std::condition_variable “variables”

I recently received a question regarding our dispatch queue implementation: ""Quote I had a question concerning the locking of the mutex in the destructor to set the boolean quit_ variable. The way I see it, the mutex protects the queue access and does not really refer to the quit_ variable. When the variable has been …

nothrow new: the Variant to Use When Avoiding C++ Exceptions

I'm a relatively young C++ developer, having spent the majority of my career programming in C. While I've devoted myself to the study of the language, I still frequently learn about new features and capabilities that surprise me. I recently learned about nothrow new, a version of the new operator which returns a nullptr on …

Choosing the Right Container: Associative Containers

I recently provided an overview of the C++ standard container types as well as high-level guidelines for selecting the right container. Today we will be taking a look at the tradeoffs of the STL associative containers. Overview Selecting between Ordered and Unordered Associative Containers Ordered Containers Unordered Containers Differentiating the Containers Further Reading Overview In …

Choosing the Right STL Container: General Rules of Thumb

In a previous article, I provided an overview of the C++ standard container types. The variety of containers and the subtle differences between them can be overwhelming, especially to new developers. Let's take a look at some quick guidelines we can use to select the right container. Think About Your Intentions The most important aspect …

std::string vs C-strings

Today we'll continue our C-to-C++ migration theme by focusing on std::string, a container-like class used to manage strings. std::string provides much more straightforward string management interfaces, allows you to utilize SBRM design patterns, and helps eliminate string management overhead. Let's start off by reviewing built-in string support in C/C++. Built-in String Support (C-style Strings) Let's …

C++: How to Utilize SBRM for C-style Interfaces and Resources

Previously I introduced the concept of scope-bound resource management, a very useful object-oriented concept available to us in C++. Unfortunately, if you’re migrating from C to C++, you likely don’t have the luxury of converting all of your legacy code to modern C++. It would still be nice to utilize SBRM strategies with our C-style …