Text Editor: Data Structures
<i>The worst way to store and manipulate text is to use an array. Firstly, the entire file must be loaded into the array first, which raises issues with time and memory. Even worse still, every insertion and deletion requires each element in the array to be moved. There are more downsides, but already this method is clearly not practical. The array can be dismissed as an option rather quickly.</i><p>The authors of the dozens of tiny editors using this &quot;structure&quot;, which were quite popular on the PC in the late 80s through early 90s, would disagree. A memcpy&#x2F;memove() runs at many GB&#x2F;s on a typical machine today, so you would have to be editing absolutely <i>huge</i> files to notice. Even back then, memory bandwidth was a few MB&#x2F;s --- still plenty fast, considering that the typical files of the time were also much smaller.<p>I can remember a time when I was attempting to write my own editor and at first spending a lot of time obsessing over the data structures (it was harder to find such information at the time) --- only to realise that a lot of the editors I&#x27;d tried, including the one I was using the most at the time --- were working perfectly well with just one big buffer.<p>I&#x27;ve opened files of a few hundred MB in Windows&#x27; Notepad, which also belongs to this family of editors; and on a machine a few years old, opening the file takes the longest because it has to be read into memory --- once it&#x27;s opened, moving around and editing lines doesn&#x27;t show much lag at all. &quot;Worse is better&quot;, indeed.