SDRAM and byte array

Hi All !

I have trouble with the SDRAM memmory, and I wrote a test program to see what happend....

#include <MemoryFree.h>
#include <Time.h>

static char stringBuffer[11] = "0123456789";

void setup() {
Serial.begin(9600);
}

void loop() {

Serial.println(stringBuffer);
Serial.print("SDRAM:");
Serial.println(freeMemory());

delay(1000);
}

In this case the sdram memory is 1815


#include <MemoryFree.h>
#include <Time.h>

static char stringBuffer[11] = "0123456789";

void setup() {
Serial.begin(9600);
}

void loop() {

Serial.println(stringBuffer);

strcpy(stringBuffer, "1111111111");
Serial.println(stringBuffer);

Serial.print("SDRAM:");
Serial.println(freeMemory());

delay(1000);
}

If I want to update the allocated byte buffer, why is consuming memmory ? How could I update buffer whidout allocateing new memory ? I just want to owwerride.

BUt in this case not allocates double size of memmory ? why ?


#include <MemoryFree.h>
#include <Time.h>

static char stringBuffer[11] = "0123456789";

void setup() {
Serial.begin(9600);
}

void loop() {

stringBuffer[0] = 'E';
stringBuffer[1] = 'z';
stringBuffer[2] = ' ';
stringBuffer[3] = 'e';
stringBuffer[4] = 'g';
stringBuffer[5] = 'g';
stringBuffer[6] = 'y';
stringBuffer[7] = ' ';
stringBuffer[8] = 'F';
stringBuffer[9] = 's';
Serial.println(stringBuffer);

stringBuffer[0] = 'i';
stringBuffer[1] = 'i';
stringBuffer[2] = 'i';
stringBuffer[3] = 'i';
stringBuffer[4] = 'i';
stringBuffer[5] = 'i';
stringBuffer[6] = 'i';
stringBuffer[7] = 'i';
stringBuffer[8] = 'i';
stringBuffer[9] = 'i';
Serial.println(stringBuffer);

stringBuffer[0] = 'v';
stringBuffer[1] = 'v';
stringBuffer[2] = 'v';
stringBuffer[3] = 'v';
stringBuffer[4] = 'v';
stringBuffer[5] = 'v';
stringBuffer[6] = 'v';
stringBuffer[7] = 'v';
stringBuffer[8] = 'v';
stringBuffer[9] = 'v';
Serial.println(stringBuffer);

Serial.print("SDRAM:");
Serial.println(freeMemory());

delay(1000);
}

First, there is no SDRAM - the AVR's RAM is fully static.
Second, please use code tags when posting code.

why is consuming memmory ?

Because of this strcpy(stringBuffer, "1111111111");

Thx for your answer !

Is it possibbile to update the buffer without consumming memmory ?

Well, the data has to come from somewhere.
My favourite to save RAM is from flash (PROGMEM)