'SRAM usage in Arduino RP2040

Is there any way to get sram usage on RP2040 processor with C/C++ Pico SDK or Arduino Mbed for RP2040. I am using an Arduino Nano RP2040 and I want to check the current memory status at runtime. In Arduino AVR it looks like this:

#ifdef __arm__
// should use uinstd.h to define sbrk but Due causes a conflict
extern "C" char* sbrk(int incr);
#else  // __ARM__
extern char *__brkval;
#endif  // __arm__

int freeMemory() {
   char top;
#ifdef __arm__
   return &top - reinterpret_cast<char*>(sbrk(0));
#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
   return &top - __brkval;
#else  // __arm__
   return __brkval ? &top - __brkval : &top - __malloc_heap_start;
#endif  // __arm__
}

But how will it be in pico?

I did not find any information about this in docs.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source