I have a problem with my Panda II and .NET 4.1. I have a lot of files in folder and I want read the first one, process it and delete it. In next round I want take another file, process it and delete it and so on. But when I have about 200 files I get out of memory exception when I try get files. The method GetFiles returns string with names of files. So if I have 200 files and each has 50 bytes long name (just for example) I need 10000 bytes but I don’t have it. But I don’t need the whole list of files. I need only one. And let’s say I don’t care which one.
Is there a way how to pick up only one file and use only small amount of memory? For example in C++ there are methods like opendir and readdir. I think the combination of both doesn’t use as much memory as GetFiles in C#.
Why I need this. I want every minute send a package of data to webserver through ethernet. But I want also data when internet connection is not available. So I store data with timestamp on SD card. Something like buffer. And when connection is back again I want send all data to web server. I was thinking about two solutions:
- Save package of data in separete files. It is easy to create small file and when connection is back again pickup some file, send it and then delete it. But there is a problem with GetFiles and memory. If the connection is gone all day there would be 1440 files. If set time interval to 5 minute I will get 288 and this is still to much for GetFiles method.
- Save all data to one file (Append at the end). But there is problem how to remove processed data. I don’t think there is a method which can remove for example first line in file. Of course I can create such method, but I thought the first option would be much easier and much faster (I think removing first line in 10kB file would be much slower).