Richard
Richard

Reputation: 389

Pico flash and heap - how much available and how much is used

I am learning how to program a Raspberry PicoW in C++ and I have two question about flash:

  1. How much of the flash is my programme taking up? With AtMega programming, the compiler would display this as a %, but I don't get that with the pico SDK and I would like to know how much bigger my programme can be.

  2. And how much of the heap in the flash is available? Is there memory available to heap some large arrays?

From the data sheet, the pico-w has 2MB of flash.

The uf2 file for my programme is 924Kb. Can I assume that my application is taking up about 924Kb of the 2Mb of flash? (~50%)

I found some functions to examine the flash:

struct mallinfo mi;
mi = mallinfo();

which gives:

Total non-mmapped bytes (arena): 51232

Total allocated space (uordblks): 44272

Total free space (fordblks): 6960

Does this mean I have about 51K of heap, and about 7K free? About 14%. I create a large buffer on the heap (41K), so that would explain the allocated space.

I also found this pair of functions:

uint32_t getFreeHeap()
{
    struct mallinfo m = mallinfo();
    return _getTotalHeap() - m.uordblks;
}

uint32_t _getTotalHeap()
{
    extern char __StackLimit, __bss_end__;
    return &__StackLimit - &__bss_end__;
}

_getTotalHeap() -> 243744

_getFreeHeap() -> 199472

243744 - 199472 = 44272

Do these numbers show that I have 44K available of the 244K of heap (~18%)?

Thank you for reading.

Upvotes: 0

Views: 64

Answers (0)

Related Questions