A SafeRefCounted example with main marked @nogc:

```
import std;
import core.stdc.stdlib;

struct Foo {
  double[] data;
  double * ptr;
  alias data this;

  @nogc this(int n) {
    ptr = cast(double*) malloc(n*double.sizeof);
    data = ptr[0..n];
    printf("Data has been allocated\n");
  }

  @nogc ~this() {
    free(ptr);
    printf("Data has been freed\n");
  }
}

@nogc void main() {
  auto foo = SafeRefCounted!Foo(3);
  foo[0..3] = 1.5;
  printf("%f %f %f\n", foo[0], foo[1], foo[2]);
}
```

Reply via email to