[Freeciv-Dev] Re: OO model for Freeciv?
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Mon, May 01, 2000 at 10:13:51PM -0400, ½²«íµØ <iquin@xxxxxxxxxx> was heard
to say:
> >s += '.';
> >
> >What is the shortest way to express this in C?
> s = strcat((char *)realloc(s , strlen(s) + 1), ".");
> Convenience sometimes makes programmers unaware of the underlying
> costs, results in less efficient codes.
This is O(n^2) in the number of times you do it. Any sane string
implementation will use a doubling-array approach, which is O(n) in the number
of times you do it (but would take too many lines of C to be written inline,
you'd need a library)
Inconvenience sometimes makes programmers take shortcuts and damn the
resulting costs, results in less efficient codes.
(Note: I also don't think rewriting Freeciv in C++ is a particularly good
idea [1], but this argument goes both ways (you can also abuse C++ in horrendous
ways to generate bad code, and I'm not very good at writing efficient code.
But I can't let a statement that that strcat call is more efficient than
the C++ construct pass :) ) )
Daniel
[1] If I had godlike powers and wanted to alter Freeciv, I would cause it to
be designed with a small C kernel and all high-level logic written in
Lisp or Scheme, a la the Sawmill window manager (to name a recent example
of this design strategy) This would be such a redesign of the current
code, though, that it'd probably be better to start from scratch, which
I have no intention of doing.
- [Freeciv-Dev] Re: OO model for Freeciv?, David Pfitzner, 2000/05/01
- [Freeciv-Dev] Re: OO model for Freeciv?, Jules Bean, 2000/05/01
- [Freeciv-Dev] Re: OO model for Freeciv?, Tony Stuckey, 2000/05/01
- [Freeciv-Dev] Re: OO model for Freeciv?, Florian Klein, 2000/05/01
- [Freeciv-Dev] Re: OO model for Freeciv?, 蔡恆華, 2000/05/01
- [Freeciv-Dev] Re: OO model for Freeciv?,
Daniel Burrows <=
- [Freeciv-Dev] Re: OO model for Freeciv?, 蔡恆華, 2000/05/01
- [Freeciv-Dev] Re: OO model for Freeciv?, 蔡恆華, 2000/05/01
- [Freeciv-Dev] Re: OO model for Freeciv?, Peter Schaefer, 2000/05/02
- [Freeciv-Dev] Re: OO model for Freeciv?, Peter Schaefer, 2000/05/02
- [Freeciv-Dev] Re: OO model for Freeciv?, Dan Ward, 2000/05/02
|
|