Hi,
I was having some surprises in Memory Leakage recently, and then, I found out that the Teensy 2.0 increases RAM usage just for having a Function defined outside a Class.
Here is the testing code:
MemoryLeakage_Teensy_2.0.ino
UselessLibrary.h
UselessLibrary.cpp
Can someone explain how this can be solved? Thanks.
I was having some surprises in Memory Leakage recently, and then, I found out that the Teensy 2.0 increases RAM usage just for having a Function defined outside a Class.
Here is the testing code:
MemoryLeakage_Teensy_2.0.ino
Code:
#include <Arduino.h>
#include "UselessLibrary.h"
// Results in 9 bytes for 'true' and 9 bytes for 'false' for the Arduino Nano Board!
// Results in 22 bytes for 'true' and 54 bytes for 'false' but only in Teensy 2.0 Board!
#define LOCAL true
void setup() {
// put your setup code here, to run once:
}
void loop() {
char initiated_string[33] = "This results in Memory Leakage!!";
if (LOCAL)
LibraryClass::locallyDefinedFunction(initiated_string);
else
LibraryClass::externallyDefinedFunction(initiated_string);
}
UselessLibrary.h
Code:
#ifndef LIBRARYCLASS_H_INCLUDED
#define LIBRARYCLASS_H_INCLUDED
class LibraryClass {
public:
static void locallyDefinedFunction(char* const string_pointer) {
// does nothing
}
static void externallyDefinedFunction(char* const string_pointer);
};
#endif // LIBRARYCLASS_H_INCLUDED
UselessLibrary.cpp
Code:
#include "UselessLibrary.h"
void LibraryClass::externallyDefinedFunction(char* const string_pointer) {
// does nothing
}
Can someone explain how this can be solved? Thanks.