Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have a number of large text files that I need to manipulate in a highly performant manner. I've decided to look into using Memory Mapped files in C# (.NET 4). However, I can't find any examples of or guidance on how to read/write to a memory mapped file that, underneath, is bound to a text file. Can anyone shed some light on this and, possibly, provide me with some examples?

If it helps, I’ll be reading text in whole lines, then altering the line and replacing it with content that may be shorter or longer than the original. After all of the manipulations are done, I want to save it back to disk as a text file.

share|improve this question
    
    
Yeah, I read that but the samples are built around random access binary files. I am sequentially processing the files and the source files are text. I have a feeling I will have to step into the byte encoding/decoding side of things, built my own cursor, etc... –  JoeGeeky Dec 2 '11 at 9:54
add comment

1 Answer 1

up vote 5 down vote accepted

I do not think you will gain much, if anything, in performance, by using memory-mapped files instead of performing normal text-file processing. From the moment that you change the length of a single line even by just one byte, the remainder of the file will need to be read, shifted by one byte, and written back to disk. From the point of view of I/O, this is equivalent to normal text-file processing: Read a line, modify it, write it, repeat. And the headache of having to do by yourself all the text processing is probably not worth the hassle.

Have you established an acceptable performance metric for your system?

Have you tried the normal text file processing approach and found it to exceed that metric before starting to look for a more efficient solution?

share|improve this answer
2  
Your comments have made me rethink this... I'm going back to the drawing board. I played around with the classes a little today and they do require a bit of extra plumbing to do what I need and I certainly don't want to reinvent the wheel. Thanks. –  JoeGeeky Dec 2 '11 at 18:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.