No, stack allocation should not destroyed

FeepingCreature feepingcreature at gmail.com
Tue Jul 19 11:19:10 UTC 2022


On Tuesday, 19 July 2022 at 11:00:58 UTC, Hipreme wrote:
> What happens if I do:
> ```d
> void setupRenderer() @nogc
> {
>     setUniform("Test", [1, 2]);
>     setUniform("Test", [1, 2, 3]);
>     setUniform("Test", [1, 2, 3, 4]);
> }
> ```
>
> Then what it happens?
> Error: `@nogc` function `setupRenderer` cannot call non- at nogc 
> function `renderer.setUniform`
> Error: `@nogc` function `setupRenderer` cannot call non- at nogc 
> function `renderer.setUniform`
> Error: `@nogc` function `setupRenderer` cannot call non- at nogc 
> function `renderer.setUniform`

>...

> So, for solving that, one must either:
>
> `setUniform("Test", [cast(float)1, 2].staticArray);`
> Or they need to actually have a float literal in the array.
>
> Actually, I think that could be one of the the worse usecases 
> for that

Just to note, even without DIP1000 you can just

void setUniform(string name, float[] vec...) { }

setUniform("Test", 1, 2);

and get a stack allocation for vec.

But what I'd do if I wanted to make fully sure is just `void 
setUniform(T...)(string name, T args)` and then build a static 
buffer manually inside `setUniform`.


More information about the Digitalmars-d mailing list