@pinned classes

Justin Spahr-Summers Justin.SpahrSummers at gmail.com
Thu Apr 1 07:27:37 PDT 2010


On Thu, 01 Apr 2010 05:27:55 -0400, bearophile 
<bearophileHUGS at lycos.com> wrote:
> 
> 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

But shouldn't the GC know the size of Foo instances? It seems like it 
should be able to rewrite any GC-managed pointers that point to 'f' or 
anywhere inside it.



More information about the Digitalmars-d mailing list