How to use destroy and free.
Tejas
notrealemail at gmail.com
Tue May 3 16:43:28 UTC 2022
On Tuesday, 3 May 2022 at 12:59:31 UTC, Alain De Vos wrote:
> Error: array literal in @nogc function test.myfun may cause a
> GC allocation
>
> @nogc void myfun(){
> scope int[] i=[1,2,3];
> }//myfun
>
> May is a fuzzy word...
For this particular piece of code, you can use a static array to
guarantee the usage of stack allocation
```d
import std;
@nogc void myfun(){
/* no need to use scope now */int[3] i=[1,2,3];//this now compiles
}//myfun
void main()
{
writeln("Hello D");
}
```
More information about the Digitalmars-d-learn
mailing list