Allocate a string via the GC

bauss jj_1337 at live.dk
Mon May 23 12:24:10 UTC 2022


On Monday, 23 May 2022 at 12:20:11 UTC, JG wrote:
> On Monday, 23 May 2022 at 11:39:22 UTC, Adam D Ruppe wrote:
>> On Monday, 23 May 2022 at 09:38:07 UTC, JG wrote:
>>> Hi,
>>>
>>> Is there any more standard way to achieve something to the 
>>> effect of:
>>>
>>> ```d
>>>   import std.experimental.allocator;
>>>   string* name = theAllocator.make!string;
>>>  ```
>>
>> Why do you want that?
>>
>> Easiest way I know of is to just wrap it in a struct, then 
>> `new that_struct`, which is also a better way for all the use 
>> cases I know.... but those use cases are pretty rare so 
>> there's probably a better way to do what you're trying to do.
>
> I am writing an interpreter and I needed access to a string via
> a pointer of type void*
>
> I ended up wrapping it in a struct since I needed another value
> anyway. Seems odd that one can't do it in a less unusual way.
>
> Thanks.

You can take the address of the string. .ptr should do it, BUT I 
think it might not always work, someone can correct me on this, 
but I believe it depends on where the memory for the string lives 
whether it works or not?


More information about the Digitalmars-d-learn mailing list