Not logged in
Log in now
Create an account
Subscribe to LWN
LWN.net Weekly Edition for May 23, 2013
An "enum" for Python 3
An unexpected perf feature
LWN.net Weekly Edition for May 16, 2013
A look at the PyPy 2.0 release
I must agree with this statement. Most of the rants about C string handling comes from people who couldn't do string handling correctly in any language.
The standard C library sucks, but you could easily do better and even create wonders with reasonable usage of alloca() and some of the C99 features or GNU extensions.
Why learn C? (O'Reilly Radar)
Posted Jun 30, 2012 0:51 UTC (Sat) by alankila (subscriber, #47141)
Posted Jun 30, 2012 3:23 UTC (Sat) by jamesh (guest, #1159)
If you have an algorithm that iteratively cuts off and processes the head of a string until the string is consumed, the way to get the tail of the string can affect the performance.
If making a new string containing the tail of the original string just references the original string data, the obvious solution may work fine. If instead it involves a memory allocation and string copy, then the algorithm may exhibit quadratic performance w.r.t. the string length.
And this isn't just a case of one string handling method being better than the other: with the first strategy, taking a 100 character slice of a 100K string might prevent the large string from being released.
For all its faults, at least these sort of trade-offs are usually visible in C string handling.
Posted Jun 30, 2012 17:03 UTC (Sat) by HenrikH (guest, #31152)
Posted Jul 3, 2012 13:36 UTC (Tue) by alankila (subscriber, #47141)
Let's just say that your point is valid and correct. It still does not make me look C-style "string" handling favorably. The few instances where you have to take a copy to detach a substring from a longer string, or to avoid quadratic performance of string concatenation loops are imho not materially significant compared to the benefits of making strings easy and nice to use.
Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds