AppliedNumeric answer
Per-thread counters · Part 2 of 3
Sixteen worker threads count the messages they handle in std::atomic<uint64_t> counts[16], a contiguous array that starts on a 64-byte cache-line boundary. Each thread increments only its own element.
You pad each counter onto its own line with struct alignas(64) Slot { std::atomic<uint64_t> n; }; and declare Slot counts[16]. How many bytes does the array take now?
Answer with a number. Fractions, powers and expressions like 23/6 or C(52,5) are read correctly in practice.
The worked solution is in Premium
The answer, the full working and the one idea to take away – for this and all 1,322 questions in the bank. Answer it in practice and your working is marked, with a known mistake named when you make one.
Learn the method
C++ for trading: RAII, moves and what belongs on the hot path
More systems and low latency questions
- Which of these is the most important thing to remove from a hot path?Applied
- On a typical 64-bit platform, what is sizeof of struct { char a; int32_t b; char c; }?Applied
- Why do low-latency C++ codebases avoid virtual function calls on the hot path?Applied
- What does std::move(x) do by itself?Applied
- A std::vector starts with capacity 1 and doubles whenever it is full.Applied
- What does returning a large std::vector by value cost in modern C++?Advanced