There are several different types in the Arduino programming language. They each have different applications that can use up the limited RAM in the Arduino. When should i use each?
Sign up
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
closed as off-topic by AsheeshR, Butzke, Ricardo, Peter R. Bloomfield, The Guy with The Hat Feb 14 '14 at 12:30This question appears to be off-topic. The users who voted to close gave this specific reason:
|
|
One should appreciate that the Arduino is an Embedded Processor. Specifically that it has limited resources of RAM and ROM(aka Flash/program space). Often is the case I see coding use the "int" defaultly. Almost sloppily. If that works great. BUT!!!! You can run out of room REAL FAST with only 2K of RAM. I would recommend that you size down your type to the minimum of what it needs to be describing it. One also gets a better understanding of what it really is and its limitations. There is no need for an array of int(16bits) from bytes that were recieved from the SPI, UART or I2C. Or a matrix of RGB's that consume 3 bytes each, being int's. You cut your capacity in half. The pro/con: PRO: using default int everywhere makes it more inter changeable. The CON is that such interchangeability can lead to unintentional casting errors. I would also recommend using C99 type def's which can be found at "avr_stdint.html">http://www.nongnu.org/avr-libc/user-manual/group_avr_stdint.html" and elsewhere. It makes things vivid, regards to this aspect. Hence a "int" would be a "int16_t", "unsigned long" be "uint32_t" etc... It is worth knowing that in some cases a byte or char can not be replaced with int8_t, as such when used with string array functions. But they are still just as vivid. |
|||||||||||||||||
|
An overview of the most commonly used variables:
Most variable declarations can be prefixed with |
|||||
|
boolean
,byte
andword
. are not standard C++. Additionally, theString
class is nothing like the C++std::string
. Perhaps a more specific question about the differences is warranted? – Peter R. Bloomfield Feb 14 '14 at 11:50