Reputation: 13
I have tool to process text. Tool has 6 memo (memoEdit - devexpress). But when user input large text (50-100k line each memo), exception thrown error out of memory
To avoid this exception, i allow user chose file to process. Tool will read file each line and process each line then write to file result.
But my problem is how to read line 1 of 6 input file at the same time ? Or line 2... line n ?
Please help.
My work is process and mix all user input to one file.
Tool work well but when export or write result file, thrown exception.
That why i think i need read input file and write result line by line. But problem is how to read 4-6 file same line at same time. Ex: read line 1 of 6 file ?
Upvotes: 1
Views: 213
Reputation: 8514
I'm not sure I get your question because it sounds trivial, but we'll get to what's troubling you by seeing if something is an answer, and if not - why.
So, here's my suggestion. It assumes you have files with equal number of lines (given that you said that you combine the content of the files). Of course, your files should probably go separately to be processed individually, but you'll get the idea.
List<System.IO.StreamReader> files = new List<System.IO.StreamReader>
{
new System.IO.StreamReader("c:\\file1.txt"),
new System.IO.StreamReader("c:\\file2.txt"),
new System.IO.StreamReader("c:\\file3.txt")
};
int lineCount = 0;
bool hasMore = true;
while(hasMore)
{
foreach(var file in files)
{
string fileLine = file.ReadLine();
hasMore = fileLine != null;
//add your processing here...
}
lineCount++;
}
file.Close();
Upvotes: 1
Reputation: 5083
I have had a similar issue before which I was able to solve by breaking the work into batches:
Done!
Upvotes: 1
Reputation: 14334
The problem is that you are running out of memory. It is that simple. The quantity of your data is exceeding your RAM. What size are the files? Add them up then compare it to the memory you have on your PC.
Remember that c# strings are Unicode - 16 bits per character. Your text files may be 8bits per character but it will always be 16 bits in memory.
Upvotes: 1