From eb54c78d740824e677567fef24ac3917e7e17173 Mon Sep 17 00:00:00 2001 From: Neil McKechnie Date: Tue, 9 Mar 2021 23:41:33 +0000 Subject: [PATCH] Change initial value for free memory. Change initial value from 32767 (maximum value of a 16-bit signed integer) to __INT_MAX__ (compiler-defined maximum value for an int). --- CommandStation-EX.ino | 4 ++-- freeMemory.cpp | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/CommandStation-EX.ino b/CommandStation-EX.ino index 4954223..6694244 100644 --- a/CommandStation-EX.ino +++ b/CommandStation-EX.ino @@ -123,8 +123,8 @@ void loop() LCDDisplay::loop(); // ignored if LCD not in use -// Report any decrease in memory (will automatically trigger on first call) - static int ramLowWatermark = 32767; // replaced on first loop + // Report any decrease in memory (will automatically trigger on first call) + static int ramLowWatermark = __INT_MAX__; // replaced on first loop int freeNow = minimumFreeMemory(); if (freeNow < ramLowWatermark) diff --git a/freeMemory.cpp b/freeMemory.cpp index f8d2a0b..f1ad965 100644 --- a/freeMemory.cpp +++ b/freeMemory.cpp @@ -32,7 +32,7 @@ extern char *__malloc_heap_start; #endif -static volatile int minimum_free_memory = 32767; +static volatile int minimum_free_memory = __INT_MAX__; static inline int freeMemory() { @@ -52,6 +52,7 @@ static inline int freeMemory() { // void updateMinimumFreeMemory(unsigned char extraBytes) { int spare = freeMemory()-extraBytes; + if (spare < 0) spare = 0; if (spare < minimum_free_memory) minimum_free_memory = spare; }