Effecent use of memory

 

Hi

This code uses uChar instead of int  to save on memory. I get compiler warning "possible loss of data due to type convesion.

Since I am not expecting the number to go above 30, why use int and waste memory?

Any suggestion to turn off this kind of warning, or what would you do?


Thanks

  uchar symbols = SymbolsTotal(true);
  for(uchar i = 0; i < symbols; i++){
 

There's absolutely no need to save memory on that.

Integer type is fine.

And remember that although you do not expect more then 30 pairs in marketwatch, the possibility of more does exist and is quite common, and that will result in an error sooner or later.

 
uchar symbols = (uchar)SymbolsTotal(true);
if you really must save memory
 
samjesse: This code uses uChar instead of int  to save on memory. I get compiler warning "possible loss of data due to type convesion.

Since I am not expecting the number to go above 30, why use int and waste memory?

Any suggestion to turn off this kind of warning, or what would you do?

You can use typecasting!

 uchar symbols = (uchar) SymbolsTotal(true);
  for(uchar i = 0; i < symbols; i++){

However, please be aware that by "saving" RAM you can actually be wasting both RAM and CPU, because internally, RAM can be aligned to larger bit-size and the CPU instructions may be useing larger bit-sized operations requiring extra steps in the conversion to and from the required bit size.

So, always test your theory to make sure that it is actually saving RAM and CPU (or not)!

 

do we save cpu or memory usage by assigning symbols?

what happens to cpu and memory usage if we just put...

for(int i = 0; i < SymbolsTotal() i++){