Software to check code and optimize it:
Always use const at the end of the declaration of the method if this method won't change the value of the inputs parameters.
Always initialize variables with a value. You can use ‘{ }’ in order to 0 initialize numeric variables or arrays.
If possible, use iterators instead of for loops
Global variables non initialized are 0
Memory Map:
The difference between semaphore and mutex is that the only thread that can unlock a mutex is the one that has blocked it while in semaphores any thread can unlock it.
Use scope in order to avoid deadlocks
Use constexpr instead of #define when possible
Use range-based for loops when possible
Use snprintf instead of sprintf: In snprintf the size is fixed while in sprintf no, so it can lead to buffer overflows.
You don't lose anything by declaring a variable inside a for loop (it won't be initialized each iteration)
Use the keyword “override” when overriding a method (redefining a method in an inherited class)
Use the keyword “static” for methods when you have a lot of instances of one class where the method is but the method would be the same for all instances. This way you only allocate one time the method in memory
Use emplace_back instead of push_back when possible
Try to avoid construction separate form asignement:
int a; a = 5;
int a = 5;
(especially when complex constructors)