Go Down

Topic: Opening multiple files simultaneously with adafruit's SD library? (Read 995 times) previous topic - next topic

liudr

Just wanted to see if it is possible to simultaneously open up to 3 files with adafruit's SD wrapper library around the SDfat lib. I tested it on one setup and it worked but someone else tested on identical setups and the second file is not recorded. This might be related to SRAM shortage but I just want to know if SRAM is enough, is opening 3 files simultaneously possible?

BTW, how much SRAM does each file roughly consume?

Thank you!

fat16lib

You can open multiple files with both the Arduino SD.h and the Adafruit version of SD.h.

Each file requires about 58 bytes of RAM.  I say about since SD.h uses malloc so the amout can vary with heap fragmentation.

SD.h is subject to memory leaks.  If you reuse a file handle without closing it, you will lose about 30 bytes each time you open a file.

SdFat does not use malloc and a each file requires 31 bytes.

liudr

fat16lib,

Thank you for your reply. I am still learning the sdfat library. The SD appealed to me as simple so I started with it. I will be switching to sdfat soon.

Regarding file handle, do you mean a File object? I do close() BTW.

fat16lib

Yes I meant a File object.  Both open for write and open for read take the same amount of memory.

Code: [Select]

File file;

  // other code

  file = SD.open("test.txt", FILE_WRITE);  // calls malloc to allocate memory

  // access file here

  file.close();  // calls free to release memory


Go Up