Opening a second copy of a file on a sd card as fast as possible

yeahtuna

Well-known member
If I already have a copy of a file open, how can I open a second copy of it as quickly as possible?

This first sd.open() operation takes about 850 uS. I assume that a chunck of that time is spent actaully looking for the file on the SD. If I want a second copy of the file (file2), is there a way to speed up the opening by using information from the file1?
Code:
file1 = sd.open(filename, FILE_READ);

//Is there was to open this quicker by uing my file1 reference?
file2 = sd.open(filename, FILE_READ);
 
Never used SD, but if I was you, I would first try to copy file1 handler in file2. Something like memcpy( file2, file1, sizeof ( put the file_handler_type here ))
But i could be totally wrong :)
 
Never used SD, but if I was you, I would first try to copy file1 handler in file2. Something like memcpy( file2, file1, sizeof ( put the file_handler_type here ))
But i could be totally wrong :)
That is a very unwise thing to do with C++ objects, just use assignment (=). If the compiler says it's not allowed there's probably a good reason.
 
What do you mean by second copy? If you open the same file twice there is still only one copy of the file, you just have two file references to it.

If you need to be able to read from two different points in the same file then you can use seek to move the read point to the required location. Or if speed is critical maybe look at caching part of the file in memory.
 
If you need to be able to read from two different points in the same file then you can use seek to move the read point to the required location.

That's definately an obvious answer that didn't occur to me. I came up with a different solution which involves keeping an extra copy of the file open so it's ready when I need it--so far it seems to be working great. At some point I will test to see if seeking is as fast and reliable. Thanks
 
Back
Top