26-10-2018, 17:39
Znalazłem kiedyś dwa przykłady jak sprawdzić wolny RAM, zapisałem sobie "na kiedyś", na razie nie miałem potrzeby testować. Możesz sobie sprawdzić:
Kod:
size_t freeRam ()
{
return RAMEND - size_t (__malloc_heap_start);
} // end of freeRam
void setup ()
{
Serial.begin (115200);
Serial.println ();
Serial.print (F("Free memory = "));
Serial.println (freeRam ());
} // end of setup
void loop () { }
/* This function places the current value of the heap and stack pointers in the
* variables. You can call it from any place in your code and save the data for
* outputting or displaying later. This allows you to check at different parts of
* your program flow.
* The stack pointer starts at the top of RAM and grows downwards. The heap pointer
* starts just above the static variables etc. and grows upwards. SP should always
* be larger than HP or you'll be in big trouble! The smaller the gap, the more
* careful you need to be. Julian Gall 6-Feb-2009.
*/
/*
void check_mem() {
//uint8_t * heapptr, * stackptr; // I declared these globally
stackptr = (uint8_t *)malloc(4); // use stackptr temporarily
heapptr = stackptr; // save value of heap pointer
free(stackptr); // free up the memory again (sets stackptr to 0)
stackptr = (uint8_t *)(SP); // save value of stack pointer
}
check_mem(); // heappstr, stackptr have been declared (as uint8_t * heapptr, * stackptr;)
Serial.print(" heapptr: "); Serial.println(*heapptr);
Serial.print("stackptr: "); Serial.println(*stackptr);
Serial.println ((int) heapptr);
*/
Miło być decenianym https://buycoffee.to/kaczakat