GC vs. Manual Memory Management Real World Comparison

Iain Buclaw ibuclaw at ubuntu.com
Wed Sep 5 06:04:49 PDT 2012


On 5 September 2012 13:27, Benjamin Thaut <code at benjamin-thaut.de> wrote:
> Am 05.09.2012 14:14, schrieb Alex Rønne Petersen:
>
>>
>> Where's the catch? From looking in druntime, I don't see where the
>> allocation could occur.
>>
>
> Everything is in object_.d:
>
>     equals_t opEquals(Object lhs, Object rhs)
>     {
>         if (lhs is rhs)
>             return true;
>         if (lhs is null || rhs is null)
>             return false;
>         if (typeid(lhs) == typeid(rhs))
>             return lhs.opEquals(rhs);
>         return lhs.opEquals(rhs) &&
>                rhs.opEquals(lhs);
>     }
>
> Will trigger a comparison of the TypeInfo objects with
> if (typeid(lhs) == typeid(rhs))
>
> Which will after some function calls trigger opEquals of TypeInfo
>
>     override equals_t opEquals(Object o)
>     {
>         /* TypeInfo instances are singletons, but duplicates can exist
>          * across DLL's. Therefore, comparing for a name match is
>          * sufficient.
>          */
>         if (this is o)
>             return true;
>         TypeInfo ti = cast(TypeInfo)o;
>         return ti && this.toString() == ti.toString();
>     }
>

This got fixed.  Said code is now:

override equals_t opEquals(Object o)
{
    if (this is o)
        return true;
    auto c = cast(const TypeInfo_Class)o;
    return c && this.info.name == c.info.name;
}

Causing no hidden allocation.


Regards
-- 
Iain Buclaw

*(p < e ? p++ : p) = (c & 0x0f) + '0';


More information about the Digitalmars-d-announce mailing list