PreviousNext
Limiting variable scope
Help > Appendix > Code Optimization > Limiting variable scope

FLASH                         RAM-               Speed

 

CC5X is not able to detect a minimal variable scope and therefore to effectively share RAM location between the variables. The latest possible variable declaration plus artificial code blocks will help to save some RAM.

 

uns8 temperature;

uns16 capture;

 

temperature = getTemperature();

bufferCOM[0] = temperature;

 

captureTicks();

capture = param3;

bufferCOM[1] = capture.low8;

bufferCOM[2] = capture.high8;

{

  uns8 temperature = getTemperature();

  bufferCOM[0] = temperature;

}

 

{

  captureTicks();

  uns16 capture = param3;

  bufferCOM[1] = capture.low8;

  bufferCOM[2] = capture.high8;

}