Effecent use of memory

To add comments, please log in or register
samjesse
645
samjesse  

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++){
Marco vd Heijden
Moderator
8176
Marco vd Heijden  

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.

Keith Watford
Moderator
14031
Keith Watford  
uchar symbols = (uchar)SymbolsTotal(true);
if you really must save memory
Fernando Carreiro
4447
Fernando Carreiro  
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)!

Revo Trades
51
Revo Trades  

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++){
To add comments, please log in or register