I'm not wanting to start a flame war on micro-optimisation, but I am curious about something.
What's the overhead in terms of memory and performance of creating instances of a type that has no intrinsic data?
For example, a simple class that implements IComparer<T> may contain only a Compare method, and no properties or fields.
class FooComprarer : IComparer<Foo>
{
public int Compare (Foo x, Foo y)
{
// blah, blah
}
}
Typical example code I've seen just calls new FooComparer(), wherever one of these is needed.
I can't imagine the instantiation cost here is very much at all, but I'm interested to know what it actually is. And how would it compare to, say, a static factory class that maintains a dictionary of types to comparers so that one comparer instance can be used everywhere it's needed.