Version 2 (Anthony Rowe, 05/21/2007 11:47 pm) → Version 3/17 (Anthony Rowe, 05/21/2007 11:50 pm)

== Nano-RK Tips and Tricks ==
Many of these suggestions are generally good practice for any resource constained development.

'''Don't allocate large data structures in functions'''
* Allocating large data structures in functions puts them on the stack. Typically your task's stack is only 128 bytes, so putting things like a network buffer on the stack will almost certainly cause a stack overflow. Instead, make large data structures global.

'''Avoid Recursive Function Calls'''
* Recursive function calls are also heavy when it comes to stack consumption. Try to avoid them whenever possible

'''Use inline'''
* When it seems fit, use "inline" to avoid pushing things onto the stack for small functions.

'''Be very careful with malloc'''
* Malloc does work, but if you frequently malloc and free memory you will create fragmentation. Eventually this fragmentation can lead to malloc failing. This is especially bad when you run your application for a few minutes and it seems fine, but then fails after a few hours. In general, avoid using malloc whenever possible. If you must, use it in situations where the code can safely continue if allocation fails.