Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!sun-barr!rutgers!mit-eddie!bu-cs!buengc!bph From: bph@buengc.BU.EDU (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: strings Message-ID: <2848@buengc.BU.EDU> Date: 13 May 89 18:43:49 GMT References: <10235@socslgw.csl.sony.JUNET> <1989May11.155935.22324@utzoo.uucp> <10245@socslgw.csl.sony.JUNET> Reply-To: bph@buengc.bu.edu (Blair P. Houghton) Followup-To: comp.lang.c Organization: Boston Univ. Col. of Eng. Lines: 30 In article <10245@socslgw.csl.sony.JUNET> diamond@diamond.csl.sony.junet (Norman Diamond) writes: >In article <1989May11.155935.22324@utzoo.uucp> henry@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?"