Loading...
Pages: [1]   Go Down
Author Topic: RamSize or RamLeft function ?  (Read 166 times)
0 Members and 1 Guest are viewing this topic.
France
Offline Offline
Sr. Member
****
Karma: 2
Posts: 378
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
Offline Offline
Brattain Member
*****
Karma: 314
Posts: 35518
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
Offline Offline
Brattain Member
*****
Karma: 248
Posts: 16535
Available for Design & Build services
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

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

Ouups !

Thanks a lot guys !
Logged

Pages: [1]   Go Up
Print
 
Jump to: