How can we measure the amount of memory consumed by a code in Arduino Due

I want to make a comparison of the amount of memory usage on different platforms. How can I measure the memory used by a particular code in Arduino Due.

Please help me.

Thanks in advance :slight_smile:

The quickest way for me is to actually compile using the IDE and see what is says. The code I posted to your question about 32*32 bit multiplication, resulted in the following message from the IDE ... not just that code but actually add the string-length example of the IDE. I had that example running earlier and simply inserted the mult code in there...

Binary sketch size: 33,400 bytes (of a 524,288 byte maximum) - 6% used
Forcing reset using 1200bps open/close on port /dev/ttyACM0
/home/scomix/wProj/software/arduino-1.5.2/hardware/tools/bossac --port=ttyACM0 -U false -e -w -v -b /tmp/build2381726136440311559.tmp/sketch_jul26a.cpp.bin -R 
Erase flash
Write 34772 bytes to flash

[                              ] 0% (0/136 pages)
[==                            ] 7% (10/136 pages)
[====                          ] 14% (20/136 pages)
[======                        ] 22% (30/136 pages)
[========                      ] 29% (40/136 pages)
[===========                   ] 36% (50/136 pages)
[=============                 ] 44% (60/136 pages)
[===============               ] 51% (70/136 pages)
[=================             ] 58% (80/136 pages)
[===================           ] 66% (90/136 pages)
[======================        ] 73% (100/136 pages)
[========================      ] 80% (110/136 pages)
[==========================    ] 88% (120/136 pages)
[============================  ] 95% (130/136 pages)
[==============================] 100% (136/136 pages)
Verify 34772 bytes of flash

[                              ] 0% (0/136 pages)
[==                            ] 7% (10/136 pages)
[====                          ] 14% (20/136 pages)
[======                        ] 22% (30/136 pages)
[========                      ] 29% (40/136 pages)
[===========                   ] 36% (50/136 pages)
[=============                 ] 44% (60/136 pages)
[===============               ] 51% (70/136 pages)
[=================             ] 58% (80/136 pages)
[===================           ] 66% (90/136 pages)
[======================        ] 73% (100/136 pages)
[========================      ] 80% (110/136 pages)
[==========================    ] 88% (120/136 pages)
[============================  ] 95% (130/136 pages)
[==============================] 100% (136/136 pages)
Verify successful
Set boot flash true
CPU reset.

If you haven't bought the Due yet, I believe you can still install the Arduino 1.5.2 IDE on your PC, tell it you are using Due board and use the Compile/Verify option to see how big your own code becomes.

About the mult question of yours... I am not sure if the generated code is using math lib for 64-bit result. Typically a 32-bit CPU will do 32x32 mult and provide the result using two 32-bit registers. But in this case, I think it may be using the math lib because without those 6 executible lines in my code, the original program size is :-

Binary sketch size: 14,712 bytes (of a 524,288 byte maximum) - 2% used.

You can do a detailed analysis of the executable by enabling the "Verbose option in IDE during Build" and look at the build output.