Go Down

Topic: 'uint8_t' instead 'Int' (Read 2 times) previous topic - next topic

Pedro Ferrer

Hello

Thanks by the tip!
I'll read!

Thanks once again
Best regards
Pedro Ferrer

maniacbug


Thanks to you, I've changed (not all yet) some 'Int' to 'uint8_t'... result... my sketch length on Mega 2560:
Before was ~133000 bytes
Now is ~113000 bytes!!!

Amazing!


This is because, as AWOL said, the int type "will require more program memory to hold the extra instructions to fetch and manipulate it" than uint8_t.

wildbill

Quote
After replace variables 'Int' 616 times by 'uint8_t' my sketch reduced from 132146 bytes to 113890 bytes using arduino.exe compiler!

Sounds well worth it. Does it still work? I'd be very nervous about the possibility for tricky bugs to arise if you didn't carefully consider the range of expected values for each int you replaced.

robtillaart

Quote
After replace variables 'Int' 616 times by 'uint8_t' my sketch reduced from 132146 bytes to 113890 bytes using arduino.exe compiler!


I was wondering why a sketch uses 616 variables?
This sounds like room for functions and arrays and refactoring

Can you post the (new) code?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pedro Ferrer

Hello


Sounds well worth it. Does it still work? I'd be very nervous about the possibility for tricky bugs to arise if you didn't carefully consider the range of expected values for each int you replaced.


Now it works... I didn't changed all the 616 vars... it was just a test to see the sketch dimension, but I can ensure that lot of them were replaced by hand.
I've found some bugs... some vars that have value '-1' and I forgot... I had to undo to 'Int' again.

The sketch is too complex... almost 2 years developing the code... you can look some movies on youtube if you look for 'COADAS+'

Thanks
Best regards
Pedro Ferrer

Nick Gammon

Quote
some vars that have value '-1'


You can use "char" instead of "byte".

The char type can hold numbers in the range -128 to +127.
http://www.gammon.com.au/electronics

maniacbug


Quote
some vars that have value '-1'


You can use "char" instead of "byte".

The char type can hold numbers in the range -128 to +127.


You CAN also use uint8_t to hold "-1" as long as you realize it's actually 255 :D

Go Up