Question about itoa()

Hi everybody, the page description of itoa() function says:

"The stdlib itoa() library routine adds around 600 bytes, the roll-your-own K&R implementation, which includes string.h, adds around 670 bytes. Using snprintf() from stdio.h adds just over 2200 bytes."

I want to know if the call of the itoa() function needs 600bytes free of the 2048bytes that has the dinamic memory of Arduino Uno.

Best regards, Ginza.

itoa() is code so it uses FLASH or PROGMEM memory. Probably it uses only a few bytes of RAM when called to hold the result and a pointer to the current digit in the char array.

Hi robtillaart, thanks for your reply. Sorry for my english.

Im trying to save each byte that has the ATMega328 on the dynamic memory. By now, I have used 1300bytes of the 2048bytes with my code and I havent finished the development.

How amount of free bytes on dynamic memory do you think is necessary to leave free to avoid system crashes ?

I suppose that is difficult to know the exact amount, because it depends on each sketch code, but perhaps there is a standard free amount of dynamic memory.

Best regards, Ginza.

How amount of free bytes on dynamic memory do you think is necessary to leave free to avoid system crashes ?

1

you should preferably not use dynamic memory as the Arduino has no memory manager. Creating some global classes at startup that allocate dynamic arrays are in fact constant so that will work.

You might move const array's e.g. text messages to PROGMEM to reduce the RAM usage.

Furthermore there is the freeRAM function that you could use to test available RAM

int freeRam () {
    extern int __heap_start, *__brkval; 
    int v; 
    return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
};

if you need a more detailed advice, please post your whole sketch so we can see how to reduce memory footprint.

How amount of free bytes on dynamic memory do you think is necessary to leave free to avoid system crashes ?
While using Uno I was OK with about 5% of RAM left.

The freeRAM function is very useful when you get bellow 10%.

I would watch any "standard" library for using int when byte will do, it is a small gain but when you need it...

I really think Due is much friendlier to anybody pushing the memory usage on Uno.
Good luck.

itoa() will require no permanent RAM. It might allocate some on the stack, which will be reclaimed when the function exits. The largest use of permanent RAM will be your buffer.

Thanks a lot to everybody, I will use the freeRAM() function to check the memory through the sketch running.

Best regards, Ginza.