Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

jdsmith

Member Since 15 Feb 2011
Offline Last Active Sep 09 2014 08:07 PM
-----

Topics I've Started

Memory efficient way to enumerate an array of FileInfo

23 August 2011 - 05:39 PM

I'm working on a Netduino Plus application that's reading/writing files to/from an SD card. I'm looking for a memory efficient way to enumerate through the list of files on the SD card. For the sake of this discussion, I don't know the names of the files on the card, so my code needs to enumerate through a list. It seems like the GetFiles() method of a DirectoryInfo uses memory in some direct proportion to the number of files (and perhaps the length of the filenames or even file size?) on the disc. As such, there's a limit to the number of files GetFiles can handle. Based on my filenames/file sizes, I'm capping out around 100 files.

Is there another way to enumerate files on the SD card? Something that does not involve GetFiles()?

My code looks similar to this:


ArrayList fileInfo = new ArrayList();
        
if (Directory.Exists(path))
     {
          DirectoryInfo dirInfo = new DirectoryInfo(path);

 
          foreach (FileInfo file in dirInfo.GetFiles())
          {
               fileInfo.Add(file);
          }
     }

The code poops out on the foreach statement (OutOfMemory exception).

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.