"immutable string" vs "const string*"

rikki cattermole rikki at cattermole.co.nz
Sun Sep 9 08:14:41 UTC 2018


On 09/09/2018 8:09 PM, Christian Mayer wrote:
> 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.

Are you aware that a string is just an alias of immutable(char)[]?

It already is a pointer with a length, just like any other slice.


More information about the Digitalmars-d-learn mailing list