Richard said:
CBFalconer said:
No, but its users might. Your ggets routine has a linear
reallocation strategy, which can have quite a serious
performance impact compared to a quadratic strategy.
You mistake efficiency in applications that will not occur for
actual efficiency. The intended, and expected, use of ggets is in
interactive input. The strings will not become unceasingly large,
so the linear reallocation is used, and is most efficient for
interactive input. Note that the system will work correctly, if
not quite as efficiently, for any length of input string. Thus the
user is not limited in application, but the normal use is
efficient. The initial allocation often suffices.
Incidentally a reasonably smart malloc package will make those
reallocs quite efficient. They simply detect that the original
assignment can be expanded in place, and avoid doing any copying.
When such an expansion is impossible they go through the full
alloc/dealloc gyration. See my nmalloc package.