>> > What's the best approch to having a common method that takes a
>> > collection ( List<> ), goes through its elements and deletes them.
[quoted text clipped - 52 lines]
> will be called. Are we not hitting extra overhead with dynamic_cast
> here?
I'm not sure if delete on an Object will add a runtime check whether it is
IDisposable. In order to call a virtual member function, you normally have
to downcast to at least the type where that member function is introduced,
and "Dispose" is introduced by IDisposable.
The runtime check is necessary when using Object, because not all objects
implement Disposable, so there's no overhead.
That's one of the reasons why the generic method could be faster, because
now there is a constraint and the compiler knows in advance that T
implements Dispose. However a cast to interface probably isn't any faster
than dynamic_cast anyway (cast to base class is very fast). The JIT only
instantiates a generic once for reference types, the same implementation is
shared for all different T unless T is a value struct. So it's not possible
for the compiler to determine the correct offset into the v-table at JIT
time, a runtime cast will be used.
vcquestions - 20 Aug 2007 19:12 GMT
> >> "vcquestions" <vcquesti...@gmail.com> wrote in message
>
[quoted text clipped - 75 lines]
>
> - Show quoted text -
crystal clear! ;) thank you!