Does to!(string)(char[]) do any memory allocation on conversion?

Mengu mengukagan at gmail.com
Mon Dec 25 14:37:01 UTC 2017


On Monday, 25 December 2017 at 14:12:32 UTC, Marc wrote:
> Does to!(string)(char[]) do any memory allocation on conversion 
> or is this similar to a cast or what else?

yes, it is allocating memory. you can test such cases with @nogc 
[0].

you can get a char[] via .dup of a string and then you can 
cast(string) if you don't want to allocate any memory.

[0] https://dlang.org/spec/attribute.html#nogc


More information about the Digitalmars-d-learn mailing list