GC vs. Manual Memory Management Real World Comparison

Benjamin Thaut code at benjamin-thaut.de
Wed Sep 5 07:59:48 PDT 2012


Am 05.09.2012 15:07, schrieb Iain Buclaw:
> On 5 September 2012 14:04, Iain Buclaw <ibuclaw at ubuntu.com> wrote:
>> 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.
>>
>>
>
> Oops, let me correct myself.
>
> This was hacked at to call the *correct* opEquals method above.
>
>
> bool opEquals(const Object lhs, const Object rhs)
> {
>      // A hack for the moment.
>      return opEquals(cast()lhs, cast()rhs);
> }
>
>
> Regards
>

Still, comparing two type info objects will result in one or multiple 
allocations most of the time.

Kind Regards
Benjamin Thaut


More information about the Digitalmars-d-announce mailing list