Since Regular Expressions seem to accept only string, the most common way to search a file is either by reading it to a single string or by reading each line in turn.
The problem is that with big files you either hold a huge string in memory or killing the GC with very large amount of strings that are created, used and left for garbage collection.
Does anyone know of a better way to access this problem?
Since Regular Expressions seem to accept only string, the most common way to search
Share
The ‘best’ way depends on your needs.
And you won’t ‘kill’ the GC with a large number of strings that quickly. Test/verify your assumptions.
When your problem is line-based, read the lines one-by-one. Prefer
File.ReadLines()overFile.ReadAllLines().If your problem spans the whole file (
RegexOptions.Multiline, maybe including line-breaks in the patterns), you will have to read it into 1 string. Use smaller files if it becomes a problem.In all cases, use common sense and/or a profiler.