Hi
Let's say I have a function:
void doSomething( File file )
What exactly the function does, is not so important, but we may assume that the file object will be used to write data to an SD card, and will again be closed within the function. Basically:
void doSomething( File file )
{
file = SD.open("FILE.TXT", FILE_WRITE);
file.print(); // arbitrary data is added
file.close();
}
Is the file object passed by value or by reference? I am worried about this because I want to avoid memory issues later on. If I can reuse one file object by reference, it is a great plus if I call doSomething( File file ) from a function that already contains a file object, ie:
void bigFunction()
{
File file;
file = SD.open("name.txt", FILE_READ);
file.read(); // arbitrary file operation
file.close();
// We are done with file, but it remains in the memory.
doSomething( file ); // Thus, reusing the same object makes sense.
}
If a copy of the file object is sent as a parameter (aka call by value), I would have another instance of the object sitting in the memory unnecessarily.
If it is sent by value, a little help adapting the syntax to pass it by reference would be appreciated.
I have been googling this, but most of the stuff I read left me uncertain. I also tried some of the RAM usage measurement functions, but their results reported no change in memory usage between the the different File and SD operations, so they also left me confused, as I expected a rise in memory usage with the initialization of the file objects.
To the slightly more experienced C++ programmers out there, this is hopefully a no-brainer.
Thanks