- Don't manage memory, manage objects: objects manage resources
- Only use memory allocation when you are implementing hardware
- Use the most appropriate smart pointer type: unique if you will need only one reference; shared if you will share it
- Use new instead of alloc and dealloc
- Use smart pointer instance members
- Use initialization lists, allocate resources in constructors
- Release resources in destructors
- Copy when resources will be used in both the destination and the source
- Move when resources will be used only in the destination scope Additional notes on values and copy/move: http://msdn.microsoft.com/en-us/library/hh438479.aspx
- Declare variables and members at the top of the scope in which they are used
- Data member lifetime is virtually overhead free (no, there is no garbage collector)
- Maintainability and simplification (stack) valued over tiny performance gain (heap); also helps eliminate memory leaks
- Confusing; rarely useful
- C++ allows you to replace a type name with a variable name.. Don't.
- Only widely used abbreviations
- Underscores should only appear in constants
- Don't mess with global namespace... no one else does, why should you
- enum class vs enum; eliminates potential collisions
- Use std::begin and std::end for types that don't already have these
- Iterator should be marked as constant, especially (and you really shouldn't do this) if you are not replacing a reference in your loop
- For example: array for fixed size collection; vector, list, map, etc for dynamic
- Use list for quick insert / removal
- Use vector if you need random access
- Use map for lookups
- Don't be afraid to use smart pointer types as element type
- Do not use pointers or complex types for keys
- Use make_pair for constructing pairs
- When a standard algorithm implementation exists for given logic, it should be used instead of writing said logic
- Reduces redundancy and increases readability
- Don't initialize things to 0
- Use atomic types and flags over mutex; use std:mutex over platform specific
- Spawn threads only when they will / can be used: default thread implementation does not consider resources
- Operations on volatile variables are not atomic and do not define behavior useful for threading
- Use atomic types and mutex
- Compile time type queries
- Static assertions