"immutable string" vs "const string*"

Christian Mayer christian at fox21.at
Sun Sep 9 08:09:11 UTC 2018


In regard of performance, why should I rather use "immutable 
string" over "const string*" (or just "string*")?

For example, as a function argument. When I have a loop which 
calls a function with a string argument. (And to avoid function 
inling in this example the function call is also used in several 
other places.) It's better to use a pointer instead of every time 
coping the content of the original string to a new immutable 
string, right? Or is the optimizer somehow treating the immutable 
string in another way I'm currently not aware of?

Is there an example of a usecase for better using "string" over 
"string*"?

Just want to figure out how to do it the "right" way.


More information about the Digitalmars-d-learn mailing list