user1677: I am using an Arduino with 2048 bytes of SRAM. I have a complex project so that it is no longer obvious how much SRAM it would use in total (there is not one large dominant object but many different routines, many libraries most of which I have not written myself etc. Each of these uses some small buffers, global variables etc.). 
Can I determine how much SRAM I have left in the live system?

user7508: Expanding on my previous comment... The RAM memory map of an AVR-based
Arduino looks like this:
┌──────┬─────┬──────┬──────────┬───────┐
│ data │ bss │ heap │→  free  ←│ stack │
└──────┴─────┴──────┴──────────┴───────┘

The data and bss sections are fixed, and their size can be known at
compile time. However, the stack and the heap grow and shrink
dynamically as the program runs. You can estimate the amount of free
memory at run time by measuring the gap between the heap and the stack.
The result may be pessimistic if the heap contains usable holes.
Here you have:

a very simple function that does exactly that, and
a more complex version that also counts the holes in the heap.


1677: <p>I am using an Arduino with 2048 bytes of SRAM. I have a complex project so that it is no longer obvious how much SRAM it would use in total (there is not one large dominant object but many different routines, many libraries most of which I have not written myself etc. Each of these uses some small buffers, global variables etc.). </p>

<p>Can I determine how much SRAM I have left in the live system?</p>
 7508: <p>Expanding on my previous comment... The RAM memory map of an AVR-based
Arduino looks like this:</p>

<pre><code>┌──────┬─────┬──────┬──────────┬───────┐
│ data │ bss │ heap │→  free  ←│ stack │
└──────┴─────┴──────┴──────────┴───────┘
</code></pre>

<p>The data and bss sections are fixed, and their size can be known at
compile time. However, the stack and the heap grow and shrink
dynamically as the program runs. You can estimate the amount of free
memory at run time by measuring the gap between the heap and the stack.
The result may be pessimistic if the heap contains usable holes.</p>

<p>Here you have:</p>

<ul>
<li><a href="https://learn.adafruit.com/memories-of-an-arduino/measuring-free-memory" rel="noreferrer">a very simple function</a> that does exactly that, and</li>
<li><a href="http://playground.arduino.cc/Code/AvailableMemory" rel="noreferrer">a more complex version</a> that also counts the holes in the heap.</li>
</ul>
