Reinventing the Wheel (or ListDictionary)

D

Doug

Not that I'd actually do this... but knowing the answer would give me a bit
more understanding of the .NET Framework and the base class libraries -
specifically how things work in relation to my own custom classes or
libraries.

We could use any of the framework's classes - but lets take, for example,
the ListDictionary (System.Collections.Specialized.ListDictionary).

When solving some programming problem, I could (1) use the ListDictionary
"as is", or (2) build and consume the equivalent functionality by creating
my own class that wraps up an array or some other data structure, then add
to that class equivalent searching algorithms, etc. to the point where I
have effectively completely duplicated all the functionality that exists in
the .NET Framework's ListDictionary. When I am done I have *exactly*
duplicated the functionality; nothing more and nothing less than what
comprises the ListDictionary. Furthermore I have used the exact same
algorithms etc that Microsoft implements in the ListDictionary. You get the
idea - mine is the exact same thing in every way with the single exception
that all the code exists in my own namespace and class and ultimately in my
own assembly.

Questions:
1. Would there be *any* runtime performance penalty (imperceptible as it may
be) in an application making use of my custom class vs the Frameworks? If
so, what specifically would cause that penalty? If no penalty, then why no
penalty?

2. Would there be any benefit at all to doing this? (and yes I understand
that whatever benefit there might be would likely be totally outweighed by
the development costs etc associated with reinventing functionality that is
already in the Framework).

Thank You!
 
N

Nicholas Paldino [.NET/C# MVP]

Doug,

See inline.
Questions:
1. Would there be *any* runtime performance penalty (imperceptible as it may
be) in an application making use of my custom class vs the Frameworks? If
so, what specifically would cause that penalty? If no penalty, then why no
penalty?

No, there would not be. Because the code is the same, with the
exception of the namespace. MS doesn't have a magic wand that they wave
over their assemblies to make them work faster. Basically, its the same
code, and the CLR will treat it the same.
2. Would there be any benefit at all to doing this? (and yes I understand
that whatever benefit there might be would likely be totally outweighed by
the development costs etc associated with reinventing functionality that is
already in the Framework).

Not really. I mean, you know that the class will not change as the
framework changes, but other than that, you are gaining nothing, except for
the extra time and effort to maintain more code now.

Hope this helps.
 
S

Sherif ElMetainy

Hello

There will be no performance penalty, or may be a little because Microsoft's
implementation is ngen'ed when you install the .NET framework, so it doesn't
have to be JIT compiled. So first access might be a little bit faster, but
other than that the performance should be the same as long as the algorithm
is the same.

The problem might occur when integrating with libraries developed by other
people. Although well designed methods should accept IList instead of
ArrayList and IDictionary instead of ListDictionary or HashTable as
parameters, some developers make methods that accept ArrayList or
ListDictionary. You can't pass an instance of your class to a method that
accepts Microsoft's ListDictionary. But for many people this may not be an
issue at all, if they don't use such libraries.

Best regards,
Sherif
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top