Re: is strlen()'s read-4-bytes-ahead a standard?
Xin LI wrote: On 2010/07/15 15:38, deeptec...@gmail.com wrote: Some C implementations use the read-4-bytes-ahead technique to speed up strlen(). Does the C standard state anything about strlen() being allowed to read past the terminating zero? It's not 4-bytes-ahead, but read a whole (aligned) word at one time. I think C standard does not dictate in this detail. OK, can anyone confirm this? But why? Just wondering. ___ freebsd-chat@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-chat To unsubscribe, send any mail to freebsd-chat-unsubscr...@freebsd.org
Re: is strlen()'s read-4-bytes-ahead a standard?
On Fri, 16 Jul 2010 09:41:23 +0200, deeptec...@gmail.com deeptec...@gmail.com wrote: Xin LI wrote: On 2010/07/15 15:38, deeptec...@gmail.com wrote: Some C implementations use the read-4-bytes-ahead technique to speed up strlen(). Does the C standard state anything about strlen() being allowed to read past the terminating zero? It's not 4-bytes-ahead, but read a whole (aligned) word at one time. I think C standard does not dictate in this detail. OK, can anyone confirm this? The only text about strlen()'s behavior in my copy of the ISO/IEC 9899:1999 (E) standard is: | 7.21.6.3 The strlen function | | Synopsis | | 1 #include string.h | size_t strlen(const char *s); | | Description | | 2 The strlen function computes the length of the string pointed | to by s. | | Returns | | 3 The strlen function returns the number of characters that | precede the terminating null character. There is no reference to *how* this may be implemented, so you can safely assume that the usual as if rules of the C standard apply. The underlying code may read a single character at a time, a word at a time, or may even call system-specific kernel calls that do 'magic' behind the scenes to compute the string length. What _really_ matters, as far as the standard is concerned, is that you get a meaningful return value that matches the current length of the input string. ___ freebsd-chat@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-chat To unsubscribe, send any mail to freebsd-chat-unsubscr...@freebsd.org
Re: is strlen()'s read-4-bytes-ahead a standard?
deeptec...@gmail.com deeptec...@gmail.com wrote: Xin LI wrote: On 2010/07/15 15:38, deeptec...@gmail.com wrote: Some C implementations use the read-4-bytes-ahead technique to speed up strlen(). Does the C standard state anything about strlen() being allowed to read past the terminating zero? It's not 4-bytes-ahead, but read a whole (aligned) word at one time. I think C standard does not dictate in this detail. OK, can anyone confirm this? When Xin LI states it, it doesn't need confirmation. ;-) You can look up for yourself, it's in section 7.21.6.3 (page 333) of ISO/IEC 9899:1999 a.k.a. C99. It only states that The strlen function computes the length of the string and The strlen function returns the number of characters that precede the terminating null character. Nothing more. But why? Just wondering. There's no reason not to read the string as aligned words. Because they're aligned, there's no risk to accidentally hit the next VM page after the end of the string. On the other hand, I don't think it is clear that doing this for strlen() would be a performance win in every situation. BTW, some languages (and also some string libraries for C) store the length separately for every string, so you don't have to iterate through the whole string to get its length. Best regards Oliver -- Oliver Fromme, secnetix GmbH Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd I suggested holding a Python Object Oriented Programming Seminar, but the acronym was unpopular. -- Joseph Strout ___ freebsd-chat@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-chat To unsubscribe, send any mail to freebsd-chat-unsubscr...@freebsd.org
Re: is strlen()'s read-4-bytes-ahead a standard?
On 16/07/2010, at 18:57, Oliver Fromme wrote: Just wondering. There's no reason not to read the string as aligned words. Because they're aligned, there's no risk to accidentally hit the next VM page after the end of the string. Unless you're calling strlen on something that isn't memory (eg memory mapped device). Although that would be dumb precisely because you don't know how it's implemented. Also the compiler would warn you because your mmap'd device pointer should be declared volatile anyway.. -- Daniel O'Connor software and network engineer for Genesis Software - http://www.gsoft.com.au The nice thing about standards is that there are so many of them to choose from. -- Andrew Tanenbaum GPG Fingerprint - 5596 B766 97C0 0E94 4347 295E E593 DC20 7B3F CE8C ___ freebsd-chat@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-chat To unsubscribe, send any mail to freebsd-chat-unsubscr...@freebsd.org
is strlen()'s read-4-bytes-ahead a standard?
Some C implementations use the read-4-bytes-ahead technique to speed up strlen(). Does the C standard state anything about strlen() being allowed to read past the terminating zero? ___ freebsd-chat@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-chat To unsubscribe, send any mail to freebsd-chat-unsubscr...@freebsd.org
Re: is strlen()'s read-4-bytes-ahead a standard?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 On 2010/07/15 15:38, deeptec...@gmail.com wrote: Some C implementations use the read-4-bytes-ahead technique to speed up strlen(). Does the C standard state anything about strlen() being allowed to read past the terminating zero? It's not 4-bytes-ahead, but read a whole (aligned) word at one time. I think C standard does not dictate in this detail. But why? Cheers, - -- Xin LI delp...@delphij.nethttp://www.delphij.net/ FreeBSD - The Power to Serve! Live free or die -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.15 (FreeBSD) iQEcBAEBCAAGBQJMP48tAAoJEATO+BI/yjfBBNwIAJrqtefoZJ90095Aurk5H9kv SQZ8wVO1vgFu4qN2yT8InuXtpCB9Q6onuFQmMphdQrbqJWIDb+lxCD8UZUp6ocZE 544RPI9kLwWfUwQ0WdrTNmdAHGIbqc6nrhlS3IwTn82NCjuFH5pEpUmt0r53b19I jy/FlJjjTSiSC32tODLa922mo1GB50CA3fFlgUVlB7PHLRvdLeE6JsmvRA89gfRi /TOIRP8X/tJeDE4yuDycRmMCvOI+hFHdFchMxYQG2bifo1aZQzny+iNRA0xvYpO7 oZble3Cgwfs+jj2RkGW/syOXtvYA1CTxAJ67vf4OCX5Facq+Yfi3pto7xbIJCKE= =rxAG -END PGP SIGNATURE- ___ freebsd-chat@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-chat To unsubscribe, send any mail to freebsd-chat-unsubscr...@freebsd.org