Are indirect objects available in D?

As I read, all objects in D are completely location independent. How is this requirement achieved?

One thing that comes to my mind is that all links are not pointers to objects, but to some proxy, so when you move an object (in memory) you just update this proxy, not all the links used in the program.

But this is just my guess. How is this done in D for real?

+4
source share
1 answer

edit: bottom line up, without a proxy object, objects are referenced directly through regular pointers. / Change

structs , , , . :

struct S {
    S* lol;
    void beBad() {
        lol = &this; // this compiler will allow this....
    }
}

S pain() {
    S s;
    s.beBad();
    return s;
}

void main() {
    S s;
    s = pain();
    assert(s.lol !is &s); // but it will also move the object without notice!
}

(EDIT: , , postblit , . , , , , , . EDIT2: , / - , postblit. , , - , . . . /edit )

, , pain , main, ( , , , , , - : " ", / ).

, , , , , ; , undefined.

. this , ( )) - . (, GC ( D )), , , , .

, - , , ( GC...)

, , , . - , -.

+5
source

Source: https://habr.com/ru/post/1531956/


All Articles