Best SD library?

Hi,

I know there are lots of topics in the internet about that. But I would like to know which is the best SD library for Arduino that fits my purposes. I was already able to write and read all the things I wanted with SD.h default library. But the limited internal memory of my Arduino (Mega) is making it reset every time. From what I read, it takes a lot of heap memory. I think this makes sense because my prog. is reseting in a function call/return. Anyway, I still could refactor the code and put a bunch of functions together and try to make this problem disappear, but I don't want to make a nasty code just to avoid memory problems. So, before that, do you guys know which SD library uses less RAM memory for FAT write/read? Yes, I need FAT because the SD card will be read in a computer and the files must be ready for opening inside Windows. Any tips? I thought of FAT16lib but I'm not really sure that is better.

If you call .print() or .println() with string constants ("string constant") you can save a bunch of SRAM space by using the F() macro: Serial.print(F("string constant"));

Since you have provided no criteria for use to use to determine what is best, only you will be able to do that.

The default SD class uses one 512 byte buffer. On the 328-based machines, that's 1/4 of the available memory. On the Mega, it's only a small portion of the available memory.

If your program is continually resetting, it is unlikely that it has to do with the SD library.

Anyway, I still could refactor the code and put a bunch of functions together and try to make this problem disappear, but I don't want to make a nasty code just to avoid memory problems.

Nasty code is what causes memory problems. It is not what cures them.

F("string constant")

Why is that?

I dont communicate via serial...only with the GPS module (so there are no prints). I have lots and lots of prints to the SD files though. As I am writing a XML file, I have to write all the tags so there are lots of prints to the files. I will try that one...

One question though: as long as the line is printed, shouldn't this memory be freed? I also am making use of 2 files in the card. First I was opening both at same time. Obviously it did not work. I have to read from one and write to another. So now I first open one to read, then close it, and then I open the second to write. Now the program runs a bit more but sill crashes. Is there any way I could manually free unused memory?

PaulS:
Since you have provided no criteria for use to use to determine what is best, only you will be able to do that.

The default SD class uses one 512 byte buffer. On the 328-based machines, that's 1/4 of the available memory. On the Mega, it's only a small portion of the available memory.

If your program is continually resetting, it is unlikely that it has to do with the SD library.

Anyway, I still could refactor the code and put a bunch of functions together and try to make this problem disappear, but I don't want to make a nasty code just to avoid memory problems.

Nasty code is what causes memory problems. It is not what cures them.

How did I do not provide criteria? Its clear that I need a library that consumes less memory (especially heap memory).

It IS related to SD card for sure.

And no, I can make a code that does not crash but very nasty. Doesnt matter if the code is clear but doesnt work....but doesnt matter if the code works but I cannot understand it next week (or who else is gonna deal with it).

F("string constant")

Why is that?

String constants take up SRAM space because all pointers are assumed to be pointers to SRAM. Before your program starts, all of the string constants are copied from FLASH to SRAM. The "F()" macro tells the compiler to keep the string constant in FLASH and casts the pointer to FlashStringHelper to let the .print() method know that it has to fetch the bytes from FLASH instead of SRAM.

I have lots and lots of prints to the SD files though.

Any prints you do with string constants will use up SRAM.

One question though: as long as the line is printed, shouldn't this memory be freed?

No. The string constants stay in SRAM forever. If you copy the string constant into an SRAM buffer it will be in SRAM twice.