Vector of Objects vs Vector of Pointers

Memory access patterns are one of the key factors for writing efficient code that runs over large data sets. In this blog post, you’ll see why there might be a perf difference of almost 2.5x (in both directions!) when working with a vector of pointers versus a vector of value types.

READ MORE...

Performance of std::string_view vs std::string from C++17

How much is std::string_view faster than standard std::string operations? Have a look at a few examples where I compare std::string_view against std::string. Intro I was looking for some examples of string_view, and after a while, I got curious about the performance gain we might get. string_view is conceptually only a view of the string: usually implemented as[ptr, length].

READ MORE...

Show me your code: std::optional

Show me your code! I’d like to run a little experiment. Let’s build a wall of examples of std::optional! Intro In the last three articles of my C++17 STL series I’ve been discussing how to use std::optional. I can talk and talk… or write and write… but I’m wondering how do you use this wrapper type?

READ MORE...

Factory With Self-Registering Types

Writing a factory method might be simple: unique_ptr<IType> create(name) { if (name == "Abc") return make_unique<AbcType>(); if (name == "Xyz") return make_unique<XyzType>(); if (...) return ... return nullptr; } Just one switch/if and then after a match you return a proper type. But what if we don’t know all the types and names upfront?

READ MORE...