Well, if you know that in general people will have relatively few insertion points, you can keep an array of pointers in the original text buffer, and when the user tries to insert it inside, you βsplitβ the buffer by creating another pointer to the rest of the buffer, doing the first pointer length so that it stops at the insertion point and adds a third pointer for the text to be inserted between them, for example:
long original text la la la ^ *^ | 2nd part 1st part
And the star points to a new text buffer, where you start adding text to paste.
When you process (or even parse) your text file, you iterate over the array of pointers, and then do your work on each buffer. Of course, if the buffer is small enough, you skip adding a new part of the buffer, but this is just a heuristic, try each one and feel that it works best.
You can also consider splitting a text file into a load of several buffers, say, every 1 MB or so, because if you upload a file to one buffer, you will need to create a new buffer for the inserted text due to size. Again, this is heuristic optimization.
Blindy Jul 02 '10 at 10:36
source share