Forgive me for beating this horse further. I am working on a logging project that requires a steady throughput to the SD card. We have some class 10 32gb cards that are taking >900ms to flush 1kb to the card while other 16gb class 10 cards achieve performance of <20ms writing the very same data. Does the community have any suggestions or ideas?
Interesting how they are the same class but one is much faster! Not an answer but have you considered using ALFAT for handling the data? I am curious if this would work better and how much better.
are you comparing performance with recently formatted SDs?
after a while, the internal tables on the SD may be fragmenting.
all SDs are not equal. I would go with the brand that works best.
@ Mike - Not just that, flash takes longer time to erase over time.
@ Gus - True!
Both brand new cards, quick formatted with default Windows 7 settings to FAT32 before insertion into the Cobra-II. The slow cards are SanDisk Ultra SDHC I 32GB Cards. The faster cards are Kingston SDHC I 16GB.
On a side note, do you have any recommendations for buffer size specifications when constructing the FileStream object? Also if I don’t manually flush the stream before the buffer runs out it crashes.
We need a small example showing the cache so we can track it down please.
I cant believe I spent 2-3 minutes trying to figure out what the “cobrall” was. (COBRALL)
I too have experienced beyond excessive write times for relatively small microSD transactions…the facts…
- NETMF 4.3QFE1/GHI SDK 2014 R4 and NETMF 4.3QFE2/GHI SDK 2015 R1/PR
- G120 HDR wired directly to SD-to-microSD adapter
- Sequence
- Enable capture
- Save 10 images to memory buffers (~300K each)
- Disable capture
- Successively write 10 images to separate files via WriteAllBytes()
- Issue .FlushAll
- Write times in excess of 60 seconds per 300K file (cringe, wail)
- Multiple microSD manufacturers and capacities tried without significant change in results
- Saw ONE rapid write sequence early in the game on a card that now manifests the issue consistently
- Cards long formatted under FAT32/4K under Win7/64
My study of this issue hasn’t been as thorough by way of microSD variety or write method implementation as other contributors to this thread…I’ll report back with additonal feedback once I’ve tried a more traditional Open, [cycle] WriteChunk, Yield [end cycle], Close, Flush…
GEB@ SIM
@ Gus -
///Mount the SD card with the following:
sd.Mount(30000);
public class SomeClass
{
private FileStream stream;
private int bufferSz;
private int bytesWritten = 0;
public SomeClass(int bufferSize = 4096)
{
buffers = bufferSize;
dataFilePath = @ "SD\";
stream = new FileStream(_dataFilePath + Extensions.GetDateTimeStamp() + ".lg", FileMode.Create, FileAccess.Write, FileShare.None, bufferSz);
}
#if DEBUG
long flushTicks;
TimeSpan flushTime;
#endif
public void Write(byte[] data, int count)
{
if (bytesWritten + count >= bufferSz)
{
#if DEBUG
flushTicks = DateTime.Now.Ticks;
#endif
stream.Flush();
#if DEBUG
flushTime = new TimeSpan(DateTime.Now.Ticks - flushTicks);
Debug.Print("Flush Occurred. Bytes: " + bytesWritten.ToString() + " MS: " + flushTime.TotalMilliseconds().ToString());
#endif
bytesWritten = 0;
}
stream.Write(data, 0, count);
bytesWritten += count;
}
}
public static class Extensions
{
public static int TotalMilliseconds(this TimeSpan ts)
{
return (ts.Days * 86400000) + (ts.Hours * 3600000) + (ts.Minutes * 60000) + (ts.Seconds * 1000) + ts.Milliseconds;
}
}
Then just write a thread to send byte arrays to the Write method. In my case I’m sending about 1kb to the Write method every second. (The rest of the code was omitted to protect the innocent… )
The SanDisk Class 10 32GB SD card (new) takes ~2200ms to flush. The Kingston Class 10 16GB SDcard takes ~40ms and switching to USB a SanDisk 8gb USB memory stick takes ~20ms! Each flush is 4093 bytes.
@ Diesel Engineer -
How about if replace
by
```cs]VolumeInfo.GetVolumes()[0].FlushAll();[/code
@ Dat - I’m happy to try this at the next opportunity. What’s the science behind this suggestion?
@ Diesel Engineer -
I personally think that vol.FlushAll() is better than stream.Flush(). Just another way to try.
Also try format that SD with NetMF, not PC.
Something like this:
Debug.Print("Formating...!");
VolumeInfo.GetVolumes()[0].Format("FAT", 0);
Debug.Print("Formatted!");