strings

Blair P. Houghton bph at buengc.BU.EDU
Sun May 14 04:43:49 AEST 1989


In article <10245 at socslgw.csl.sony.JUNET> diamond at diamond.csl.sony.junet
(Norman Diamond) writes:
>In article <1989May11.155935.22324 at utzoo.uucp> henry at utzoo.uucp (Henry
>Spencer) writes:
>>Improvements to C library routines are quite possible.
>>One convention is not intrinsically worse than the other.
>
>How do you improve a C library routine to look in a string descriptor
>to just grab the current length of the string?  In other languages,
>libraries can do that.  [...] On the other hand,
>a correct strlen() function has to scan every byte of (for example)
>my 300K array.  Or my 509-byte array, maybe 510-byte array, but several
>thousand times.  It seems intrinsically worse to me.

Slower, yes.  Worse, no.

If it's that way, then use the string functions so they only
have to do it once, and store the knowledge as structs which
include the string and a length counter, and then use your own
library to implement string functions that know about your
string-data structure.

However, a strlen() that doesn't count the char's can be fooled,
and any data structure you devise can be inadequate by someone
else's standards, while not retaining the the elegant completeness
of just storing the data as is.

				--Blair
				  "Or am I overlooking something
				   obvious...again?"



More information about the Comp.lang.c mailing list