D
David
My AIM is the performance, so what is better to use, static method or
instance method? and why?
Thanks a lot
instance method? and why?
Thanks a lot
David said:My AIM is the performance, so what is better to use, static method or
instance method? and why?
Girish bharadwaj said:One can argue that the initial creation of the object required for instance
might add a few extra IL than the call to a static.
Girish bharadwaj said:One can argue that the initial creation of the object required for instance
might add a few extra IL than the call to a static.
Richard Blewett said:well at this point we are arguing over minutae that will be
completely irrelevant when the method actually *does* something.
Although academically interesting about the one or two IL
instructions these sort of things are pretty much never where
performance issues are based. It only leads people into premature
optization (spending time optimizing things that are probably not a
bottleneck anyway).
The fundemental thing about static and instance methods is that they
have different use cases, not that one is faster than the other.
irrelevant when the method actually *does* something. Although academicallyRichard Blewett said:well at this point we are arguing over minutae that will be completely
different use cases, not that one is faster than the other.The fundemental thing about static and instance methods is that they have
nntp://news.microsoft.com/microsoft.public.dotnet.framework/ said:Girish bharadwaj said:One can argue that the initial creation of the object required for instance
might add a few extra IL than the call to a static.
Yes - I had assumed the creation of the object had been factored in
elsewhere, and that the OP was only asking about the calling of
methods, rather than the creation of objects as well.
Calling an instance method *does* have the tiny extra overhead of
checking that the target isn't null, admittedly.
--
Jon Skeet - <[email protected]>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004
[microsoft.public.dotnet.framework]
one of the tenets of OOP. Specifically, you have no encapsulation,Matt Berther said:Hello Girish,
One could also argue that this leads to a very sloppy design that violates
irrelevant when the method actually *does* something. Although academicallyRichard Blewett said:well at this point we are arguing over minutae that will be completely
different use cases, not that one is faster than the other.The fundemental thing about static and instance methods is that they have
nntp://news.microsoft.com/microsoft.public.dotnet.framework/ said:Girish bharadwaj said:One can argue that the initial creation of the object required for instance
might add a few extra IL than the call to a static.
Yes - I had assumed the creation of the object had been factored in
elsewhere, and that the OP was only asking about the calling of
methods, rather than the creation of objects as well.
Calling an instance method *does* have the tiny extra overhead of
checking that the target isn't null, admittedly.
--
Jon Skeet - <[email protected]>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.766 / Virus Database: 513 - Release Date: 17/09/2004
[microsoft.public.dotnet.framework]
the posters needs then they probably shouldn't be using .NET for theirRichard Blewett said:Refusing to let this rest ;-)
If the cost of static as opposed to instance invocation is important to
Umm, While I agree that it does stop you from having any of the OOness
in your class, I am not sure if its sloppy design just because its
static.
I can think of many use cases where a static method would just do fine
for me. They serve the same purpose as global functions used to in
C++. I can do it better in C# since i can encapsulate them within an
assembly.
one of the tenets of OOP. Specifically, you have no encapsulation,
inheritance *or* polymorphism with a purely static class.