Pages: [1]   Go Down
Author Topic: Opening multiple files simultaneously with adafruit's SD library?  (Read 909 times)
0 Members and 1 Guest are viewing this topic.
Central MN, USA
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7197
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged


0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1636
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 73
Posts: 7197
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged


0
Offline Offline
Edison Member
*
Karma: 64
Posts: 1636
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Code:
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
Logged

Pages: [1]   Go Up
Jump to: