@pinned classes
bearophile
bearophileHUGS at lycos.com
Thu Apr 1 02:27:55 PDT 2010
Justin Spahr-Summers:
> I think the D2 spec puts restrictions on what you can do with GC-
> allocated pointers (can't convert them to integers, can't perform
> arithmetic on them outside of their bounds, etc.), and I think they're
> restrictive enough that a copying garbage collector could work with no
> changes to compliant code.
Without annotations here the compiler has to find by itself that instances of this class is harder to move:
import std.c.stdio: printf;
class Foo {
int x;
int* ptrx;
this(int xx) {
this.x = xx;
this.ptrx = &(this.x);
}
}
void main() {
auto f = new Foo(10);
printf("%d %d\n", f.x, *f.ptrx);
auto p = f.ptrx;
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list