DLL symbol identity

Laeeth Isharc via Digitalmars-d digitalmars-d at puremagic.com
Mon May 11 18:28:43 PDT 2015


On Monday, 11 May 2015 at 20:53:40 UTC, Benjamin Thaut wrote:
> Am 11.05.2015 um 21:39 schrieb Laeeth Isharc:
>> On Monday, 11 May 2015 at 12:54:09 UTC, Benjamin Thaut wrote:
>>>> and why does it not map well to D ?
>>> D uses tons of templates everywhere. Even type information 
>>> for non
>>> templated types is generated on demand and stored in comdats 
>>> which can
>>> lead to duplicate symbols the same way it does for templates. 
>>> In D the
>>> dynamic cast is basically the default and you have to force 
>>> the
>>> compiler to not use a dynamic cast if you care for 
>>> performance.
>>
>> Sorry for the rookie question, but my background is C rather 
>> than C++.
>> How do I force a static cast, and roughly order magnitude how 
>> big is the
>> cost of a dynamic cast ?
>>
>> Would you mean for example rather than casting a char[] to a 
>> string
>> taking the address and casting the pointer?
>
> Dynamic casts only apply to classes. They don't apply to basic 
> types.
>
> Example
>
> object o = instance;
> SomeClass c = cast(SomeClass)instance; // dynamic cast, checks 
> type info
> SomeClass c2 = cast(SomeClass)cast(void*)instance; // unsafe 
> cast, simply assumes instance is SomeClass
>
> If you do the cast in a tight loop it can have quite some 
> performance impact because it walks the type info chain. 
> Walking the type info hirarchy may cause multiple cache misses 
> and thus a significant performance impact. The unsafe cast 
> literally does not anything besides copying the pointer.

aha - thank you.  I appreciate it.  Laeeth.


More information about the Digitalmars-d mailing list