Articles & Books

How to optimize C and C++ code in 2018--Iurii Krasnoshchok

Are you aware?

How to optimize C and C++ code in 2018

by Iurii Krasnoshchok

From the article:

We are still limited by our current hardware. There are numerous areas where it just not good enough: neural networks and virtual reality to name a few. There are plenty of devices where battery life is crucial, and we must count every single CPU tick. Even when we’re talking about clouds and microservices and lambdas, there are enormous data centers that consume vast amounts of electricity.

Even boring tests routine may quietly start to take 5 hours to run. And this is tricky. Program performance doesn‘t matter, only until it does.

A modern way to squeeze performance out of silicon is to make hardware more and more sophisticated...

Trip Report: C++ Standards Meeting in San Diego, November 2018--Botond Ballo

New trip report.

Trip Report: C++ Standards Meeting in San Diego, November 2018

by Botond Ballo

From the article:

A few weeks ago I attended a meeting of the ISO C++ Standards Committee (also known as WG21) in San Diego, California. This was the third committee meeting in 2018; you can find my reports on preceding meetings here (June 2018, Rapperswil) and here (March 2018, Jacksonville), and earlier ones linked from those. These reports, particularly the Rapperswil one, provide useful context for this post...

How to Design Function Parameters That Make Interfaces Easier to Use (3/3)--Jonathan Boccara

The end.

How to Design Function Parameters That Make Interfaces Easier to Use (3/3)

by Jonathan Boccara

From the article:

This is the final article in the series about function parameters. This series contains:

  • Part 1: interface-level parameters, one-parameter functions, const parameters,
  • Part 2: calling contexts, strong types, parameters order,
  • Part 3: packing parameters, processes, levels of abstraction.

Exploring C++20 - Designated initialisers--Tobias Widlund

Will be very useful.

Exploring C++20 - Designated initialisers

by Tobias Widlund

From the article:

Compared to many other C++20 additions this one is quite small, only needing a single box of explanation on cppreference. Despite this, I quite like the feature as it helps code that uses aggregate initialisation to be more readable and less error prone - both are well needed in that area!

Quick Q: Type inference of 'auto' when using range-for loop in multidimensional arrays

Quick A: a pointer has no size information.

Recently on SO:

Type inference of 'auto' when using range-for loop in multidimensional arrays

The type of row is deduced to be int*. That means, just like any other int*, the compiler doesn't know how big the array it points to is, or even that it's a pointer to the first element of an array at all. All of that information is lost when an array decays into a pointer to its first element.

If instead you use something like

for (auto& row : ia) //<-- NOTE: row is now a reference
    for (int* j = std::begin(row); j != std::end(row); ++j)
        std::cout << *j << '\n';

then the type of row will be deduced to int (&)[4]: reference to an array of 4 ints. The length information is retained, so std::begin and std::end have the information they need.

PS: Just as a note: range-for works by using std::begin and std::end internally, so the above can be a bit more concisely written as

for (auto& row : ia)
    for (auto j : row)
        std::cout << j << '\n';

Threads are not the answer -- Lucian Radu Teodorescu

You have a performance problem, you want to employ parallelism, you start adding threads... pause a moment and reflect

Threads are not the answer

by Lucian Radu Teodorescu

From the article:

Whatever the problem is, threads are not the answer. At least, not to most software engineers.

In this post I will attack the traditional way in which we write concurrent applications (mostly in C++, but also in other languages). It’s not that concurrency it’s bad, it’s just we are doing it wrong.

The abstractions that we apply in industry to make our programs concurrent-enabled are wrong. Moreover, it seems that the way this subject is thought in universities is also wrong.

Look ma, no locks -- Lucian Radu Teodorescu

How can you solve the core problem in concurrent programming? How can you avoid using locks, but still have safety for your resources?

Look ma, no locks

by Lucian Radu Teodorescu

From the article:

We previously argued that threads are not the answer to parallelism problems, and also that we should avoid locks as much as possible. But how can we have a world in which threads do not block each other?

We want to explore here a systematic way for replacing locks (mutexes, read-write mutexes, semaphores) in our systems with tasks. We argue that there is a general schema that allows us to move from a world full of locks to a world without locks, in which the simple planning and execution of tasks makes things simpler and more efficient.

How to Design Function Parameters That Make Interfaces Easier to Use (2/3)--Jonathan Boccara

Agree with the logic?

How to Design Function Parameters That Make Interfaces Easier to Use (2/3)

by Jonathan Boccara

From the article:

Let’s continue exploring how to design function parameters that help make both interfaces and their calling code more expressive.

If you missed on the previous episode of this topic, here is what this series of articles contains:

  • Part 1: interface-level parameters, one-parameter functions, const parameters,
  • Part 2: calling contexts, strong types, parameters order,
  • Part 3: packing parameters, processes, levels of abstraction.