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

Temtaime temtaime at gmail.com
Mon Dec 25 14:37:52 UTC 2017


On Monday, 25 December 2017 at 14:37:01 UTC, Mengu wrote:
> 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

dup allocates memory too


More information about the Digitalmars-d-learn mailing list