Javari's Reference Immutability
Regan Heath
regan at netwin.co.nz
Thu Jul 27 18:54:33 PDT 2006
On Thu, 27 Jul 2006 18:39:29 -0600, Hasan Aljudy <hasan.aljudy at gmail.com>
wrote:
> You say that Java's String class implies alot of copying, therefor it's
> bad. However, you fail to realize that copying when modifying is exactly
> what COW stands for. COW is a kind of honor-system protocol implemented
> by phobos. Everytime phobos thinks it needs to modify a string which it
> doesn't own, it makes a copy first to keep the original string intact.
> In Java, this can be done by creating a StringBuffer from the String
> (which creates a copy), after that, any modification you make to
> StringBuffer happens in-place; no needless copying.
Sure. But are you trying to tell me that this..
String foo(String a) { .. return modified a .. }
String bar(String a) { .. return modified a .. }
String baz(String a) { .. return modified a .. }
String bob(String a) { .. return modified a .. }
String s = foo(bar(baz(bob("test"))));
Will result in _no_ needless copying?
Regan
More information about the Digitalmars-d-learn
mailing list