Pages: 1 [2]   Go Down
Author Topic: 'uint8_t' instead 'Int'  (Read 2305 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 205
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello

Thanks by the tip!
I'll read!

Thanks once again
Best regards
Pedro Ferrer
Logged

Seattle, WA
Offline Offline
God Member
*****
Karma: 11
Posts: 673
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


New Jersey
Online Online
Faraday Member
**
Karma: 67
Posts: 3701
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 217
Posts: 13739
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Rob Tillaart

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

0
Offline Offline
Full Member
***
Karma: 0
Posts: 205
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18810
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


Seattle, WA
Offline Offline
God Member
*****
Karma: 11
Posts: 673
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley-grin
Logged


Pages: 1 [2]   Go Up
Jump to: