Articles & Books

Implementing Queues for Event-Driven Programs--“No Bugs” Hare

An interesting article:

Implementing Queues for Event-Driven Programs

by “No Bugs” Hare

From the article:

We’ve already discussed things related to sockets; now let’s discuss the stuff which is often needed (in particular, it is of Utmost Importance when implementing Reactors), but which is not that common to be universally available as a part of operating system.

I’m speaking about queues. And not only just about “some” queue, but about queues which have certain properties desirable for our Reactors a.k.a. ad-hoc Finite State Machines a.k.a. Event-Driven Programs.

Quick Q: c++ lambda capture by value

Quick A: A capture by value is a copy.

Recently on SO:

c++ lambda capture by value

That's because the variable is captured by value (i.e. copied) only once, when you define the lambda. It's not "updated" as you may believe. The code is roughly equivalent to:

#include <iostream>

int x = 0;
struct Lambda
{
    int _internal_x; // this is used to "capture" x ONLY ONCE
    Lambda(): _internal_x(x) {} // we "capture" it at construction, no updates after
    void operator()() const
    {
        std::cout << _internal_x << std::endl;
    }
} qqq;

int main()
{
    qqq();
    x = 77; // this has no effect on the internal state of the lambda
    qqq();
}

VoidParam Puzzle -- Alex Marmer

Alex Marmer has openend a puzzle.

VoidParam Puzzle 

From the article:

How to handle 'void' parameter passed in a macro. He provides a solution as well.

In case that you have other or better solutions, don't hesitate to use the comment option on this site.

Quick Q: If nullptr_t isn't a keyword, why are char16_t and char32_t?

Quick A: To allow overloading with the underlying types of uint_least16_t and uint_least32_t

Recently on SO:

If nullptr_t isn't a keyword, why are char16_t and char32_t?

The proposal itself explains why: to allow overloading with the underlying types of uint_least16_t and uint_least32_t. If they were typedefed this wouldn't be possible.

Define char16_t to be a distinct new type, that has the same size and representation as uint_least16_t. Likewise, define char32_t to be a distinct new type, that has the same size and representation as uint_least32_t.

[N1040 defined char16_t and char32_t as typedefs to uint_least16_t and uint_least32_t, which make overloading on these characters impossible.]

As for why they aren't in the std namespace, this is for compatibility with the original C proposal. C++ prohibits the C definitions from appearing in its own version of <cuchar>

[c.strings] / 3

The headers shall not define the types char16_t, char32_t, and wchar_t (2.11).
The types then would need to be global typedefs, which carries its own set of issues such as
typedef decltype(u'q') char16_t;

namespace foo {
  typedef int char16_t;
}

The reason for std::nullptr_t not being a keyword can be found in the question you linked

We do not expect to see much direct use of nullptr_t in real programs.
making nullptr_t the real exception here.

 

C++ for Games: Performance, Allocations and Data Locality -- Sergey Ignatchenko

BB_part094_BookChapter013a_v1-640x427.pngWell-illustrated, and well-illustrated, gems:

C++ for Games: Performance, Allocations and Data Locality

by Sergey Ignatchenko

From the draft chapter:

One further thing to keep in mind with regards to 90-10 (or 70-30) rule is that even if only performance of 10% of the code matters, the rest of the code can still affect performance of critical 10% in a Pretty Bad Way :-( ...

ignatchenko-1.PNG