A gap buffer in computer science is a dynamic array that allows efficient insertion and deletion operations clustered near the same location. Gap buffers are especially common in text editors, where most changes to the text occur at or near the current location of the cursor. The text is stored in a large buffer in two contiguous segments, with a gap between them for inserting new text. Moving the cursor involves copying text from one side of the gap to the other (sometimes copying is delayed until the next operation that changes the text). Insertion adds new text at the end of the first segment. Deletion increases the size of the gap.
Text in a gap buffer is represented as two literal strings, which take very little extra space and which can be searched and displayed very quickly, compared to more sophisticated data structures such as linked lists. However, operations at different locations in the text and ones that fill the gap (requiring a new gap to be created) may require copying most of the text, which is especially inefficient for large files. The use of gap buffers is based on the assumption that such recopying occurs rarely enough that its cost can be amortized over the more common cheap operations.
Read more about Gap Buffer: Example
Famous quotes containing the word gap:
“She isnt harassed. Shes busy, and its glamorous to be busy. Indeed, the image of the on- the-go working mother is very like the glamorous image of the busy top executive. The scarcity of the working mothers time seems like the scarcity of the top executives time.... The analogy between the busy working mother and the busy top executive obscures the wage gap between them at work, and their different amounts of backstage support at home.”
—Arlie Hochschild (20th century)