- Code level optimization
such as
1. Optimize function calls
- use fast call, which doesn't use the stack but uses some processor registers. This is limited only when the parameters are not greater than 64 bit.
2. Optimize repeated calls
Use inline functions and macros instead of calling functions for small procedures, which abuse the stack.
3. Allocate memory all at once
instead of re-allocating memory each time you add an element.
4. Use objects instead of heap pointers as much as you can.
5. Be wise in using loops.