Go Down

Topic: RamSize or RamLeft function ? (Read 434 times) previous topic - next topic

Grag38

As we know, sometimes by doing mistakes in programming we can get ram oversize.

I don't mean abour buffer overflow or similar, but just datas the grow and goes over the available ram.

Does it exist a way of checking it ? If not can we hope one day getting a such kind of function ? Like

RamSize() would return the length of full rame of an arduino.
RameLeft() would return tha available that is not allocated.

So from it would allow us to check if the ram that is spent during a program is stable or continue to grow.

Best Regards

PaulS

Quote
Does it exist a way of checking it ?

There are a couple of methods. Search for FreeMem(ory).

CrossRoads

Another user did this (defining all the variables needed, serial.begin, etc)

Code: [Select]

void loop()
{
Serial.print("free memory = ");
Serial.print(availableMemory());
Serial.print(" - memory used = ");
Serial.println(2048-availableMemory());
}

int availableMemory()
{
  int size = 8192;
  byte *buf;
  while ((buf = (byte *) malloc(--size)) == NULL);
  free(buf);
  return size;
}
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Grag38


Go Up