Turn GC allocated string into a scoped heap allocation

Steven Schveighoffer schveiguy at gmail.com
Thu Dec 13 13:46:47 UTC 2018


On 12/13/18 4:38 AM, Per Nordlöw wrote:
> How do I turn the GC-allocation in toLower() to a scoped heap allocation 
> together with toLowerInPlace() in
> 
> void f(const scope const(char)[] expr)
> {
>      import std.uni : toLower;
>      loweredExpr = toLower(expr); // temporary
>      // use loweredExpr as key in hash table
> }
> 
> when `loweredExpr` is used as a temporary inside `f`?

If you use loweredExpr as a key in a builtin AA, then you need to make 
it a heap allocation, because the GC cleans up AAs.

-Steve


More information about the Digitalmars-d-learn mailing list