Are D classes always garbage collected?
vladimir at thecybershadow.net
Wed Dec 21 19:21:50 PST 2011
On Thursday, 22 December 2011 at 02:29:10 UTC, Froglegs wrote:
> From what I understand D classes are reference types, which
> would imply to me that they are either always garbage collected
> or rather less likely, reference counting.
They are garbage-collected.
> Which is fine and all, but since structs don't support virtual
> functions, doesn't this pretty much force you to use classes
> and therefor GC if you want virtual functions?
You can allocate classes anywhere, if you're OK with forfeiting
safety guarantees. For example, see emplace in std.conv:
> So why don't structs support virtual funtions? I would like to
> have a type that is not GC'd or ref counted or any other
> nonsense, but supports virtual functions..
Value type polymorphism has shown to be problematic. One notable
problem is object slicing:
> Am I missing something here? Thanks
I *think* the language allows implementing something akin to
value type polymorphism (sans syntax sugar), but currently the
required compiler features (alias this, compile-time
symbol/address evaluation) are not implemented well-enough to
test my idea.
More information about the Digitalmars-d-learn