Skip to content

Commit

Permalink
Update cpp.md
Browse files Browse the repository at this point in the history
Signed-off-by: Dennis Eichhorn <spl1nes.com@googlemail.com>
  • Loading branch information
spl1nes authored Jul 28, 2024
1 parent 35c1c15 commit 2066a60
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions standards/cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down

0 comments on commit 2066a60

Please sign in to comment.