I’m using a FEZ Cobra II with .NET Micro Framework SDK 4.3.2.
I’m facing a problem of extra-slow write on SD card and USB pen drive.
This is a snippet of code I used to approximately measure the write time, for different file sizes:
while (fffSize < 2000000) { // 2000000
string fffName = e.Volume.RootDirectory + @"\hello" + fffSize.ToString() + ".txt";
if (!File.Exists(fffName)) {
Debug.Print(System.DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + " - Started populating " + fffSize.ToString() + "-length array");
//File.Delete(
//byte[] data = System.Text.Encoding.UTF8.GetBytes("This string will go in the file!");
data = new byte[fffSize];
for (i=0; i<data.Length; i++)
data[i] = 48;
// write the data and close the file
FileStream FileHandle = new FileStream(fffName, FileMode.Create);
Debug.Print(System.DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + " - Started writing " + fffName);
FileHandle.Write(data, 0, data.Length);
FileHandle.Close();
e.Volume.FlushAll();
data = null;
Debug.Print(System.DateTime.Now.ToString("dd-MM-yyyy HH:mm:ss") + " - Finished writing " + fffName);
//mySdCard.Unmount();
//mySdCard.Dispose();
//mySdCard = null;
}
fffSize *= 5;
}
And this is the debug output:
01-06-2011 00:05:23 - Started populating 1-length array
01-06-2011 00:05:23 - Started writing \SD\hello1.txt
01-06-2011 00:05:24 - Finished writing \SD\hello1.txt
01-06-2011 00:05:24 - Started populating 5-length array
01-06-2011 00:05:24 - Started writing \SD\hello5.txt
01-06-2011 00:05:25 - Finished writing \SD\hello5.txt
01-06-2011 00:05:25 - Started populating 25-length array
01-06-2011 00:05:26 - Started writing \SD\hello25.txt
01-06-2011 00:05:27 - Finished writing \SD\hello25.txt
01-06-2011 00:05:27 - Started populating 125-length array
01-06-2011 00:05:27 - Started writing \SD\hello125.txt
01-06-2011 00:05:28 - Finished writing \SD\hello125.txt
01-06-2011 00:05:28 - Started populating 625-length array
01-06-2011 00:05:28 - Started writing \SD\hello625.txt
01-06-2011 00:05:30 - Finished writing \SD\hello625.txt
01-06-2011 00:05:30 - Started populating 3125-length array
01-06-2011 00:05:30 - Started writing \SD\hello3125.txt
01-06-2011 00:05:33 - Finished writing \SD\hello3125.txt
01-06-2011 00:05:33 - Started populating 15625-length array
01-06-2011 00:05:34 - Started writing \SD\hello15625.txt
01-06-2011 00:05:44 - Finished writing \SD\hello15625.txt
01-06-2011 00:05:45 - Started populating 78125-length array
01-06-2011 00:05:47 - Started writing \SD\hello78125.txt
01-06-2011 00:06:42 - Finished writing \SD\hello78125.txt
01-06-2011 00:06:42 - Started populating 390625-length array
01-06-2011 00:06:56 - Started writing \SD\hello390625.txt
01-06-2011 00:11:03 - Finished writing \SD\hello390625.txt
The write time is so huge (4 minutes for 400 Kb) that I don’t think I need some “fine tuning”, I need to complete refactor the architecture or even change the hardware.
The same SD card, inserted in my laptop, has “normal” write time. The write/copy of files bigger than 1 Mb takes just “a while”.
When I try to copy/write files on USB pen drive, the write time is about the same as on SD.