On Wednesday, 7 October 2015 at 09:49:27 UTC, Marc Schütz wrote:
On Tuesday, 6 October 2015 at 17:03:07 UTC, bitwise wrote:
On Tuesday, 6 October 2015 at 06:45:47 UTC, Jonathan M Davis wrote:
On Monday, 5 October 2015 at 23:08:37 UTC, bitwise wrote:
Well, again that has it's pros and cons. This is why I just want a normal language solution like DIP74.

They're not the same thing at all. scoped is supposed to put the class on the stack, not the heap. And it's not ref-counted. It's so that you can create a class object in place, use it, and throw it away without doing any heap allocation. Essentially, it allows you to use a class as if it were a non-copyable struct. Even if we end up with ref-counting supported in the language, it doesn't obviate the need for scoped classes. They're for different use cases.

- Jonathan M Davis


On Monday, 5 October 2015 at 18:18:15 UTC, bitwise wrote:
The deterministic destruction is actually what I'm after.

For my purposes, they are pretty much the same.

So again, I'll paste the same example:

class Texture { }
class Texture2D : Texture {
    this() { /* load texture... */ }
~this { /* free texture */ } // OOPS, when, if ever, will this be called?
}

Memory is not only thing that has to be cleaned up.

    Bit

import std.stdio;
import std.typecons;

class Texture {
    void bar() {
        writeln("Texture.bar");
    }
}

class Texture2D : Texture {
    this() { writeln("this()"); }
    ~this() { writeln("~this()"); }
    override void bar() {
        writeln("Texture2D.bar");
    }
}

void foo(Texture texture) {
}

void main() {
    auto texture = scoped!Texture2D();
    texture.bar();
    foo(texture);
}


RefCounted isn't implemented for classes, but there's no reason why it shouldn't work.


Really, I don't get why everyone wants to have builtin refcounting, when all that's required is a working way to make escape-proof references.

Because there is no guarantee that others, who use your code, get it right and use those constructs.

Reply via email to