Mega Memory

Hi all,

I wrote a rather large program on my mega and was wondering if generally 1.5K of free memory is enough to ensure a smooth ride. I know it depends on the amount of variables I use in my functions. But I think I am safe there... I was wondering is there anything else I need to concern myself with?

I included some very simple debug functions accessible via usb. I calculate my free memory with a function I found on this forum :

    #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__
    }

I have not yet ran into unexpected behaviour but I'd ask it here anyway just to be on the safe side. And some of you always provide insight and advice I never thought of before.

kind regards, Kevin

was wondering if generally 1.5K of free memory is enough to ensure a smooth ride.

I want to drive to a certain town and I want to know if 5 gallons of gasoline is generally enough to get somewhere. Will I be able to reach the town I want to go to?

Your question is absolutely impossible to answer without details. Post your code if you really want an answer about memory.

I totally understand.

On the other hand, my code is over 4000lines of code. Don't think anyone would want to go through that in their free time for free... Which I also totally understand...

But thanks for the answer anyway!

Kevin77:
I totally understand.

On the other hand, my code is over 4000lines of code. Don't think anyone would want to go through that in their free time for free... Which I also totally understand...

But thanks for the answer anyway!

So it's a pretty short code you're saying?