user27363: What are some of the best programming practices that can be adopted while coding sketches for Arduino, so that it uses the least memory and performance should not suffer from memory outage, and still the code be robust?
From the link: https://www.arduino.cc/en/Products/Compare
I have learned that the Uno has 32 KB of Flash memory. The maximum available is in the MEGA with 256 KB. I think Uno and Mega are the most widely used by people.

user8033: Keep in mind that RAM is even less. 32KB is a fair lot of code, since C/C++ is highly efficient. "Don't save **** in RAM."
If you need to load images into a display, save the images on an SD card. And "stream" it to the display. You can read and transmit the bytes one by one, or 10 by 10 or something.
Also, if you need long strings, you can use the "flashStringHelper" to store the string in flash memory. For example: println(F(”Error message: Couldn't connect to server));. By using F() around the string, you save valuable bytes.
Not using Arduino code, but pure AVR-C/C++, can save you a little also. (Will also save the bootloader piece of memory, if you program directly with a programmer.)
If you use Arduino, know how it works. The Arduino serial library uses ~256 or 500 bytes (I believe) as a buffer. You can change this if you need it for other applications.
Keep in mind that your saving technique depends on what resources are low. If you need to do a lot simultaneously, it's better to write non-blocking code.
But also remember: Don't optimize unless it's actually needed! Or, actually set measurable and realistic requirements, optimizing something to be "as fast as possible" can take infinite amounts of time... Run a google search on "premature optimization" as the old folks in the field like to call it.

user7508: Paul covered the most important points. This answer is intended to be a
complement to his.
First, you should keep in mind the general rules, which are more
important than the more specific ones. The general rule for saving RAM
is: be aware of what you are storing, and do not store anything you do
not really need. The general rule for saving flash is: be aware of what
you are doing, and do not do anything you do not really need.
Now, a few specific tips:
Use the const qualifier for declaring constants (e.g.
const int ledPin = 13;). The compiler will optimize-out the storage of
the constant and use immediate addressing instead.
Use PROGMEM for arrays of constants.
Whenever possible, use static memory (globals and static locals)
rather than heap allocation (malloc() and new). This will prevent
memory fragmentation and make the memory usage more predictable (only
the stack holds dynamic memory): you know at compile time, rather than
run time, whether you are low in RAM.
For the same reason, prefer C strings (char *) over String objects.
Use the C99 types int8_t and uint8_t whenever 8 bits are enough for
your integer variables.
Use the static qualifier for functions that will be used only in the
same source file, especially for functions that are called only from one
place. This gives the compiler more optimization opportunities.
If you need to optimize,
use avr-nm to know what is
consuming your precious RAM.

27363: <p>What are some of the best programming practices that can be adopted while coding sketches for Arduino, so that it uses the least memory and performance should not suffer from memory outage, and still the code be robust?</p>

<p>From the link: <a href="https://www.arduino.cc/en/Products/Compare" rel="nofollow noreferrer">https://www.arduino.cc/en/Products/Compare</a></p>

<p>I have learned that the Uno has 32 KB of Flash memory. The maximum available is in the MEGA with 256 KB. I think Uno and Mega are the most widely used by people.</p>
 8033: <p>Keep in mind that RAM is even less. 32KB is a fair lot of code, since C/C++ is highly efficient. "Don't save **** in RAM."</p>

<p>If you need to load images into a display, save the images on an SD card. And "stream" it to the display. You can read and transmit the bytes one by one, or 10 by 10 or something.</p>

<p>Also, if you need long strings, you can use the "flashStringHelper" to store the string in flash memory. For example: <code>println(F(”Error message: Couldn't connect to server));</code>. By using <code>F()</code> around the string, you save valuable bytes.</p>

<p>Not using Arduino code, but pure AVR-C/C++, can save you a little also. (Will also save the bootloader piece of memory, if you program directly with a programmer.)</p>

<p>If you use Arduino, know how it works. The Arduino serial library uses ~256 or 500 bytes (I believe) as a buffer. You can change this if you need it for other applications.</p>

<p>Keep in mind that your saving technique depends on what resources are low. If you need to do a lot simultaneously, it's better to write non-blocking code.</p>

<p>But also remember: Don't optimize unless it's actually needed! Or, actually set measurable and realistic requirements, optimizing something to be "as fast as possible" can take infinite amounts of time... Run a google search on "premature optimization" as the old folks in the field like to call it.</p>
 7508: <p>Paul covered the most important points. This answer is intended to be a
complement to his.</p>

<p>First, you should keep in mind the general rules, which are more
important than the more specific ones. The general rule for saving RAM
is: be aware of what you are storing, and do not store anything you do
not really need. The general rule for saving flash is: be aware of what
you are doing, and do not do anything you do not really need.</p>

<p>Now, a few specific tips:</p>

<p>Use the <code>const</code> qualifier for declaring constants (e.g.
<code>const int ledPin = 13;</code>). The compiler will optimize-out the storage of
the constant and use immediate addressing instead.</p>

<p>Use <code>PROGMEM</code> for arrays of constants.</p>

<p>Whenever possible, use static memory (globals and <code>static</code> locals)
rather than heap allocation (<code>malloc()</code> and <code>new</code>). This will prevent
memory fragmentation and make the memory usage more predictable (only
the stack holds dynamic memory): you know at compile time, rather than
run time, whether you are low in RAM.</p>

<p>For the same reason, prefer C strings (<code>char *</code>) over <code>String</code> objects.</p>

<p>Use the C99 types <code>int8_t</code> and <code>uint8_t</code> whenever 8 bits are enough for
your integer variables.</p>

<p>Use the <code>static</code> qualifier for functions that will be used only in the
same source file, especially for functions that are called only from one
place. This gives the compiler more optimization opportunities.</p>

<p>If you need to optimize,
<a href="https://arduino.stackexchange.com/a/20541">use <code>avr-nm</code></a> to know what is
consuming your precious RAM.</p>
