J
jacob navia
Flash Gordon a écrit :
Ahhh OK. You do not use strcat.
But if you do a strchr, for instance, instead of just doing ONE test for
equality for some character you must do TWO tests because you should
test if you have reached the terminating zero...
Using length delimited strings this is reduced to a memchr.
Ahh but obviously you do NOT use strchr either.
Yes, it will be slower. In a normal PC you will notice the difference
after some billion additions.
But you are using a very error prone construct. Do you test
ALWAYS beforehand and test CORRECTLY that you are not going just one
byte beyond the length of the string?
OF COURSE YOU never do such mistakes, your code is always 100%
right the first time.
But not everyone is like you see?
There are stupids like me that make mistakes sometimes.
But... that is the same as length delimited strings... If you keep a
pointer to the end of the string it is conceptually the same as having a
length stored somewhere.
Of course, but then, you can't write:
String s = "abcd";
s[2] = 'm';
but you have to write:
String s = CreateStringFromCharP("abcd");
AssignCharAt(s,2,'m');
This means that porting the old code to the new code is much more difficult.
Yes, like the string library of lcc-win32. Nice isn't it?
The string library is not "right for all uses" but I do not see why it
should not be right for C.
Why C must be kept artificially at such a low level that no sensible
programming is possible?
If you like those strings in other languages why not doing it in C?
jacob
Strangely enough, my programs don't depend on doing lost of strca and
strlen calls.
Ahhh OK. You do not use strcat.
But if you do a strchr, for instance, instead of just doing ONE test for
equality for some character you must do TWO tests because you should
test if you have reached the terminating zero...
Using length delimited strings this is reduced to a memchr.
Ahh but obviously you do NOT use strchr either.
So tell me, if I'm adding one character at a time to a string, keeping a
pointer to the end of the string, how is something equivalent to:
*p++ = whatever;
going to be slower than something equivalent to:
*p++ = whatever;
increment the length of the string p points in to
It seems to me that the latter is going to be slower.
Yes, it will be slower. In a normal PC you will notice the difference
after some billion additions.
But you are using a very error prone construct. Do you test
ALWAYS beforehand and test CORRECTLY that you are not going just one
byte beyond the length of the string?
OF COURSE YOU never do such mistakes, your code is always 100%
right the first time.
But not everyone is like you see?
There are stupids like me that make mistakes sometimes.
The same applies to pieces of code I have that build up strings from
constant strings. They keep track of the end of the string and a lot of
the time they know in advance how long the string is that will be added.
But... that is the same as length delimited strings... If you keep a
pointer to the end of the string it is conceptually the same as having a
length stored somewhere.
There is no system that is going to be the fastest in every situation,
and if I want counted strings I can implement them just as Paul Heisch
(sorry, I've probably spelt your name wrong) has.
Of course, but then, you can't write:
String s = "abcd";
s[2] = 'm';
but you have to write:
String s = CreateStringFromCharP("abcd");
AssignCharAt(s,2,'m');
This means that porting the old code to the new code is much more difficult.
For some of my string handling I far prefer the way other languages do
it where you don't have to worry about allocating space but instead the
buffer grows as you add to it.
Yes, like the string library of lcc-win32. Nice isn't it?
It does a lot to get rid of buffer
overflows, but that does not mean I think it is right for all uses or
for C.
The string library is not "right for all uses" but I do not see why it
should not be right for C.
Why C must be kept artificially at such a low level that no sensible
programming is possible?
If you like those strings in other languages why not doing it in C?
jacob