Mail Archives: djgpp/1999/11/15/14:43:27
Alain Magloire (alainm AT news DOT mcgill DOT ca) wrote:
> Malcolm (donald DOT mcleanNOdoSPAM AT talk21 DOT com DOT invalid) wrote:
> : What does strset do ? I imagine it sets a string to all one
> : character. This is easy to code
[...]
> Then, in that case you are better off with memset() which on most
> OS/libc coded in assembly for speed.
Wrong, at least for some applications. The difference is that you have
to know the length of the string to be 'blanked out', before you can
call memset(), i.e. strset(string, c) would be equivalent to
memset(string, c, strlen(string));
That's two loops over the string, one to find its end, the second to
fill it with 'c'. Almost certainly slower than strset, if that is
implemented in the straightforward way demonstrated by the posting you
answered to. Two loops doing so little are practically always slower
than one, even if both of them are especially cleverly written, and
the single loop is just compiled ordinarily.
--
Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de)
Even if all the snow were burnt, ashes would remain.
- Raw text -