I take that to mean that foo starts at address 272. Presuming that it is the last allocated variable, it would appear therefore that there are 272 bytes of RAM in use already. Now I can account for some of them:
34 bytes for the HardwareSerial instance (Serial)
64 bytes for the Serial transmit buffer
64 bytes for the Serial receive buffer
4 bytes for the Serial transmit buffer head and tail pointers
4 bytes for the Serial receive buffer head and tail pointers
9 bytes for keeping track of millis / micros
That adds up to: (34 + 64 + 64 + 4 + 4 + 9) = 179
So, where do the last 272 - 179 = 93 bytes go? What are they used for?
I ask because with only 2048 bytes of RAM, losing 93 would seem to be a misfortune.
[quote author=what uses ram]00800100 00000002 D __malloc_heap_end
00800102 00000002 D __malloc_heap_start
00800104 00000002 D __malloc_margin
00800106 00000010 V _ZTV14HardwareSerial
00800116 B __bss_start
00800116 D __data_end
00800116 D _edata
00800116 00000001 B foo
00800117 0000009d B Serial
008001b4 00000001 b timer0_fract
008001b5 00000004 B timer0_millis
008001b9 00000004 B timer0_overflow_count[/quote]
EDIT: The length of serial is different also, which probably accounts for the 10 extra bytes.
Whatever the overhead was, it must have been resolved.
I knew I had forgotten something: RAM starts at 0x100 because the first 256 bytes are used to address hardware registers.
So:
00800100 00000002 D __malloc_heap_end
00800102 00000002 D __malloc_heap_start
00800104 00000002 D __malloc_margin
00800106 00000010 V _ZTV14HardwareSerial
00800116 B __bss_start
00800116 D __data_end
00800116 D _edata
00800116 00000001 B foo
foo is at 0x116 (278) which is therefore 0x16 bytes from the start of RAM.
00800100 00000002 D __malloc_heap_end
00800102 00000002 D __malloc_heap_start
00800104 00000002 D __malloc_margin
00800106 00000010 V _ZTV14HardwareSerial <--- whatever this is!
00800116 B __bss_start
00800116 D __data_end
00800116 D _edata
I read that as adding on another 22 bytes. So we still have 93 - 22 = 71 to go.
holmes4:
A look at the IDE generated main.cpp (or is it .c) may show something. Any local vars there will be on the stack for the life time of the sketch.
Mark
#include <Arduino.h>
int main(void)
{
init();
#if defined(USBCON)
USBDevice.attach();
#endif
setup();
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
return 0;
}