LWN.net Logo

Null-Terminated Strings

Null-Terminated Strings

Posted Nov 18, 2010 12:44 UTC (Thu) by Kwi (subscriber, #59584)
In reply to: Null-Terminated Strings by pr1268
Parent article: Ghosts of Unix past, part 3: Unfixable designs

A better suggestion might be D-style strings, which are dynamic arrays of char. In D, a dynamic array is a (pointer, length) tuple. This gives you the ability to work on substrings without having to allocate new memory, since a substring is nothing more than a new reference to the same character data.

(Incidentally, Java strings work the same way behind the scenes, but are immutable, which I guess is what you object to when you call them inefficient?)

Of course, one problem with this suggestion is that it doubles the size of a string reference (8 bytes on 32-bit architechtures, 16 bytes on 64 bit architechtures).


(Log in to post comments)

Null-Terminated Strings

Posted Nov 18, 2010 16:14 UTC (Thu) by pr1268 (subscriber, #24648) [Link]

> (Incidentally, Java strings work the same way behind the scenes, but are immutable, which I guess is what you object to when you call them inefficient?)

Exactly. And, my semi-rhetorical question immediately after that ("is there a better way?") begs the question of whether the Sun engineers who developed the Java language imposed that immutability for thread safety (since thread safety was/is a primary goal of the Java language). I don't know for sure; just going off intuition here.

Null-Terminated Strings

Posted Nov 19, 2010 10:07 UTC (Fri) by mfedyk (guest, #55303) [Link]

python has this immutable storage for values as well, but then the stopped and made the GIL...

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds