Articles & Books

The Proxy Pattern -- Rainer Grimm

Untitled.pngPlaying the classics, at arm's length...

The Proxy Pattern

by Rainer Grimm

From the article:

A proxy controls access to another object, allowing you to perform additional operations before or after you access the original object. Sound familiar?

Which idiom is characteristic of C++? Right: RAII (Resource Acquisition Is Initialization). RAII is the C++ way to implement the Proxy Pattern. Here are the facts about the Proxy Pattern. ...

Using final in C++ to improve performance -- Niall Cooling

Screenshot_2022-11-16_163427.pngWhen having the "last word" makes stuff go faster...

Using final in C++ to improve performance

by Niall Cooling

From the article:

The final specifier was introduced in C++11 to ensure that either a class or a virtual function cannot be further overridden. However, as we shall investigate, this also allows them to perform an optimization known as devirtualization, improving runtime performance.

 

For Software Performance, the Way Data is Accessed Matters! -- Ivica Bogosavljević

Screenshot_2022-11-12_150618.pngAs Crocodile Dundee famously said, "That's not a loop, that's a loop." Just programmers having fun:

For Software Performance, the Way Data is Accessed Matters!

by Ivica Bogosavljević

From the article:

In our experiments with the memory access pattern, we have seen that good data locality is a key to good software performance. Accessing memory sequentially and splitting the data set into small-sized pieces which are processed individually improves data locality and software speed.

In this post, we will present a few techniques to improve the memory access pattern and increase data locality. The advantage of this approach is that the changes are localized in the algorithm itself, i.e. there is no need to change the data layout or the memory layout. The disadvantage is that the algorithms often become more difficult to understand and modify. ...

[... and deep inside the article ...]

Notice that, because the whole cache line is brought from the memory to the data cache, after accessing a[j][i] we can access a[j][i + 1]cheaply, since these two pieces of data belong to the same cache line. The problem in our case is that if n is large, access to a[j][i + 1] will come much after a[j][i] and by that time a[j][i + 1] will be evicted from the data cache. ...

The Facade Pattern -- Rainer Grimm

Untitled.pngPlaying the classics...

The Facade Pattern

by Rainer Grimm

From the article:

The key idea of the Facade Pattern is to provide a simplified interface to a complex system... 

The Facade Pattern is an ideal starting point for decoupling complex systems by introducing layers. Additionally, it can be used as a starting point for deprecating the old interface.

Here are the facts. ...

Improving my C++ time queue -- Marius Elvert

Tick, tock...

Improving my C++ time queue

by Marius Elvert

From the article:

Another code snippet that can be found in a few of my projects is the “time queue”, which is a simple ‘priority queue’ style data structure that I use to defer actions to a later time. ...

Lifetime extension of temporary objects in C++: common recommendations and pitfalls

After reading this article, you will learn the following: ways to extend the lifetime of a temporary object in C++, various tips and tricks; pitfalls of the lifetime extension that a C++ programmer may face.

Lifetime extension of temporary objects in C++: common recommendations and pitfalls

by Evgeny Neruchek

From the article:

You can extend the lifetime of a temporary array by referencing one of its elements. C++ has a special mechanism for this. But I would recommend you using it only in the disputes with your co-workers (and maybe in metaprogramming with the old C++ standards), since this mechanism is not so easy-to-use. However, using this mechanism does not result in dangling references, and the lifetime of the temporary array is extended to the lifetime of the reference to its element.

Convenient Unicode UTF-8 UTF-16 Conversion Functions for Windows C++ Code -- Giovanni Dicanio

In Windows C++ programming many times there's a need to convert text between UTF-8 and UTF-16 encodings.

Convenient Unicode Conversion Functions for Windows C++ Code

by Giovanni Dicanio

From the article:

I published on GitHub a header-only library (Utf8Conv) that implements some convenient functions to convert text between UTF-8 and UTF-16 Unicode encodings.

I developed the library using Visual Studio 2019 with C++17 features enabled.

The Bridge Pattern -- Rainer Grimm

Of Bridges and Pimpls:

The Bridge Pattern

by Rainer Grimm

From the article:

In C++, a simplified version of the Bridge Pattern is often used. ... The key idea of the Pimpl Idiom is that the implementation of the class is hidden behind a pointer. Here is a recipe for implementing the Pimpl Idiom: ...

 

The power of ref-qualifiers -- Andreas Fertig

overload171cover.pngNew in this month's Overload magazine:

The power of ref-qualifiers

by Andreas Fertig

From the article:

... What I have illustrated is that there is an issue with range-based for-loops. In (1), we call GetKeeper().items() in the head of the range-based for-loop. By doing this, we create a dangling reference.

ref-qualifiers to the rescue

Now, this brings us to ref-qualifiers. They are often associated with move semantics, but we can use them without move. However, we will soon see why ref-qualifiers make the most sense with move semantics.

A version of Keeper with ref-qualifiers looks like Listing 2...