@nogc and exceptions

Vladimir Panteleev via Digitalmars-d digitalmars-d at puremagic.com
Fri Sep 12 05:47:44 PDT 2014


On Friday, 12 September 2014 at 03:37:10 UTC, Jakob Ovrum wrote:
> I can think of a couple of ways to go:

> 1) The most widely discussed path is to allocate exception 
> instances statically, either in global memory or TLS. 
> Currently, this has a few serious problems:

Another problem with this is that you'll need to change every 
instance of "new FooException" to something else.

Here's a crazy idea that will never fly:

1. Opt-in reference counting for classes. This needs 
language/compiler support because currently we can't have both 
reference counting and inheritance. For example, you could 
annotate Throwable as @refcounted, and all descendants get it 
automatically. The ref-counting overhead of exceptions should be 
acceptable (even with locks), since exceptions should be 
exceptional.

2. Bring back the currently-deprecated new/delete operator 
overloading.

If we could have reference-counted classes that are allocated on 
the C heap, and keep the "new FooException" syntax, the problem 
could be solved globally and transparently. Reference counting 
implies that copies done using memcpy/unions/etc. will not be 
tracked, but nobody does that with exception objects, right?


More information about the Digitalmars-d mailing list