Workaround for typeid access violation

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Tue Jun 16 15:21:28 PDT 2015


On 6/16/15 4:30 PM, Etienne wrote:
> On Tuesday, 16 June 2015 at 20:08:36 UTC, rsw0x wrote:
>> You're attempting to use GC for a problem that they don't solve
>> because you don't have other tools to fix it. When all you have is a
>> hammer, everything looks like a nail.
>
> Well no, I have plenty of tools. I use a memory library that does a wide
> range of everything I need https://github.com/etcimon/memutils .. It's
> not like I'm reliant only on it, like it's my hammer and I only see nails..

Finalizers cannot access external GC memory. period. It's just not 
supported.

http://dlang.org/class.html#destructors

"This means that when the garbage collector calls a destructor for an 
object of a class that has members that are references to garbage 
collected objects, those references may no longer be valid. This means 
that destructors cannot reference sub objects."

If you want to manage memory from a GC'd object, you can use C malloc 
and C free.

Or, you can write your own GC that solves this problem that Sun/Oracle 
couldn't :)

In all seriousness, you could potentially have exceptions to this rule, 
but it would take a lot of cajoling of druntime and some funky @UDA magic.

-Steve


More information about the Digitalmars-d mailing list