Skip to content

MEMORY_PRINT_TOTALSIZE is off by one byte #5

@philj404

Description

@philj404

This is for an Arduino UNO, which has 2048 bytes of total RAM.

Run the following sketch "GetMemoryTotalSize.ino":

#include <MemoryUsage.h>

// Simple example to report memory TOTAL size

void setup() {
    Serial.begin(115200);
    delay(1000);
    Serial.println(F( "Running " __FILE__ ", Built " __DATE__));
    Serial.println();

    MEMORY_PRINT_TOTALSIZE
}

void loop() {
    // User reads output from setup().
}

Your serial monitor generates an output something like this:

Running C:\Users\philk\OneDrive\Documents\Arduino\GetMemoryTotalSize\GetMemoryTotalSize.ino, Built Jun  4 2021

SRAM size:2047

NOTE: The RAM size reported is 2047 bytes (not 2048 bytes).

This is because the END macro returns the address of the last byte of RAM (not the byte after it). So beginning and end are inclusive limits.
It is harder to recognize problem because the start of RAM is at 0x100, so it's harder to tell where 2k byte RAM boundaries should really belong (particularly as decimal numbers).

See #4 for a fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions