In article <44e28b53-fb6c-4b13-a2d5-a5efd560e188
@h31g2000yqd.googlegroups.com>,
says...
[ ... ]
> > Offhand, I can only think of one operation (pasting a large
> > chunk of text) that it _might_ make faster (if you could just
> > link in the pasted block instead of copying it). In general,
> > it sounds to me like a lose-lose situation -- slower
> > operation, and more complex implementation.
>
> Implementing a gap buffer isn't that trivial, either.
It's hardly what I'd call tremendously difficult. Way back when, I
wrote a split-buffer editor in Turbo Pascal 2.0. As I recall, it was
reasonably complete and usable in something like two weeks (and that,
of course, with quite a minimal standard library by modern
standards).
> > The only of those that's of any concern at all is moving
> > between marks. To move between marks, you copy all the text
> > between the marks from one side of the gap to the other. With
> > marks more than a few tens of megabytes apart, it's going to
> > be difficult to implement that in the 100 ms (or so) to be
> > perceived as "instant". A couple hundred ms isn't too
> > terrible, but much beyond that can start to bother the user.
>
> Just out of curiousity, I ran a couple of tests on my machine,
> with a buffer containing 10 million characters, over a total
> buffer size of 12,5 million characters. I get the following
> times:
>
> Move the cursor from the position 10 to 10 before the end, and
> back, alternately, in a gap buffer:
> 11.2 ms per move with char
> 28,0 ms per move with wchar_t
> Insert or delete at the position 10, alternatively ("flat"
> buffer:
> 6.9 ms per operation with char
> 16.8 ms per operation with wchar_t
> Those aren't what I'd consider prohibitive times. And the
> simplest implementation is clearly the flat buffer, which is in
> practice probably faster than the gap buffer for the most
> frequent operations, and acceptably fast for the least frequent.
You could be right, but I'm a bit less convinced. About the only
operation for which it's faster is moving the cursor, but it's not
going to be a lot faster even for that. To move by increments of
something like a word or a line, you still have to read through the
data to find the next whitespace or newline, so you haven't saved
much even at best.
The only places I can see it saving a substantial amount of time
would be moving to an explicit position (e.g. a mark, or beginning or
end of file).
> (Admittedly, this is a machine which was installed only a few
> weeks ago: A PC running under Ubuntu 9.04 (Linux 2.6), with
> 3.2GB real memory and four Intel Xeon processor cores at
> 2.00GHz.)
For a job like this, CPU speed won't usually make a lot of
difference; the bottleneck will almost certainly be main-memory
bandwidth.
> Agreed. And since just using an std::vector in the most obvious
> manner seems fast enough, and is surely the simplest solution...
Regardless of which implementation I was going to use, I'd create a
small buffer manager class to give a reasonable interface -- and I'd
expect that buffer manager to take a matter of hours to implement for
either a plain vector or a split buffer. In fact, most of the
implementation for either one is so obvious that the limitation for a
lot of it is likely to be typing speed...
--
Later,
Jerry.