Menu

#10 FART can miss search string instances in text / binary modes

open
nobody
None
5
2009-10-25
2009-10-25
Theo
No

PROBLEM:
FART can miss search string instances if the search string instances are broken by memory buffer boundaries. This applies to both text files (only if line length is over 8192) and to binary files.

FART reads data into a buffer that is 8192 bytes long, looks for the search string within that buffer, flushes the buffer to disk and then reads more data into the same buffer. Unfortunately if a search string instance is cut into 2 parts, which end up in different buffer reads, the program will miss that string instance. Consider a file that consists of 8190 A's followed by ABAB. If we try to replace the ABAB string, it will not be found because the first buffer read of 8192 bytes will only load the first part of the search string, and only a subsequent read will load the remaining part.

SOLUTION:
Make the buffer consist of 8192 bytes plus some extra bytes (namely the length of the search string minus 1). Then after file read #1, move the extra number of bytes from the back of the buffer to the beginning of the buffer, read extra data and perform search.

Changes to the code are too complicated to post here.

Discussion


Log in to post a comment.

MongoDB Logo MongoDB