From 2066a6093ffe0de896f651581b9cf36b854be0d4 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 28 Jul 2024 03:37:24 +0200 Subject: [PATCH] Update cpp.md Signed-off-by: Dennis Eichhorn --- standards/cpp.md | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/standards/cpp.md b/standards/cpp.md index fa13dc7..a147100 100755 --- a/standards/cpp.md +++ b/standards/cpp.md @@ -11,6 +11,24 @@ The reason for the strong focus on C is that we **personally** believe that C is C/C++ solutions should be valid on Windows 10+ and Linux. +## Performance + +When writing code keep the following topics in mind: + +* Branching / Branchless programming +* Instruction tables and their latency / throughput +* Cache Sizes +* Cache Line Size +* Cache Locality +* Cache Associativity +* Memory Bandwidth +* Memory Latency +* Prefetching +* Alignment / Packing +* Array of Structs vs Struct of Arrays +* SIMD +* Choosing correct data types + ## Namespace ### use @@ -23,28 +41,6 @@ Namespaces must never be globally used. This means for example `use namespace st Be careful when you use unsigned and signed integers. When using unsigned integers the compiler may create additional instructions depending on the situation since it must support integer wrapping. -## Structs - -Make sure structs don't have too much overhead due to alignment padding. Re-ordering struct members can fix a lot of padding overhead. - -```c++ -// sizeof == 12 -struct Bad { - bool a; - int b; - bool c; -}; -``` - -```c++ -// sizeof == 8 -struct Good { - int b; - bool a; - bool c; -}; -``` - ## Templates Don't use C++ templates.