Searching/replacing text in large text files
-
Part of my project is to search/replace or add text in large text files (over 4MB). The sequential approach seems to be very time consuming, therefore I started to think about other methods/procedures. Do you have/know any suggestions, www links, code snippets where I could start from? Thanks in advance, Stan
-
Part of my project is to search/replace or add text in large text files (over 4MB). The sequential approach seems to be very time consuming, therefore I started to think about other methods/procedures. Do you have/know any suggestions, www links, code snippets where I could start from? Thanks in advance, Stan
Look. I've worked with large files - it was 0.5 GB - 1.5 GB. It was realy large and search and replace took hours with DOS-made program. To impove it I compiled another program. One of the ideas was - first allocate enough memory. You probably can allocate all 4 MB in memory. Second, the program will work much faster if it will work not with bytes, but with DWORD. So, I packed chars in DWORDs by 4 where it was possible. Third, check only first DWORD, if it is equal, compare all. Make a loop with offset by DWORD. After you passed all file, increment it, and so three times to make full search. This algorithm a litle bit more complicated, but I've got speed of like it was just read and write - something like 10-15 minutes. Hope this will help.