Pages: [1]   Go Down
Author Topic: RamSize or RamLeft function ?  (Read 340 times)
0 Members and 1 Guest are viewing this topic.
France
Offline Offline
Sr. Member
****
Karma: 2
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 547
Posts: 46003
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Does it exist a way of checking it ?
There are a couple of methods. Search for FreeMem(ory).
Logged

Global Moderator
Boston area, metrowest
Online Online
Brattain Member
*****
Karma: 436
Posts: 23633
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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;
}
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

France
Offline Offline
Sr. Member
****
Karma: 2
Posts: 380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ouups !

Thanks a lot guys !
Logged

Pages: [1]   Go Up
Jump to: