Update cpp.md

Signed-off-by: Dennis Eichhorn <spl1nes.com@googlemail.com>
This commit is contained in:
Dennis Eichhorn 2024-07-28 03:37:24 +02:00 committed by GitHub
parent 35c1c1536c
commit 2066a6093f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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.