locked
Static Class Instance RRS feed

  • Question

  • Hi All,

     

    Is there any performance issue of using Single Static Class Instance with large amount of methods??

     

     


    Happy Coding, RDRaja
    Thursday, July 28, 2011 2:05 PM

Answers

  • There are other cost involved, such as generating and JIT an XML serialization assembly for the web service proxy that depends on the class size. There are other one-time initialization involved such as detecting IE's network settings.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    • Proposed as answer by JohnGrove Friday, July 29, 2011 7:17 PM
    • Marked as answer by Cookie Luo Tuesday, August 2, 2011 2:07 AM
    Friday, July 29, 2011 4:13 PM

All replies

  • What sort of issues were you thinking of?  How do you mean large?  Large as in number of methods, or large in that it has a lot of data fields?

    The main issue would be that if the data is mutable and your program is multi-threaded, you would need to synchronize access to the static object's underlying mutable fields which can lead to contention.  If your program is single-threaded though, this wouldn't be an immediate issue.

    Certainly, though, a large class would tend to have maintenance issues since it may possibly fail the single responsibility principle (SRP).


    James Michael Hare

    Blog: http://www.geekswithblogs.net/BlackRabbitCoder

    Twitter: @BlkRabbitCoder

    There are 10 kinds of people in the world: those who know binary and those who don't...



    Thursday, July 28, 2011 2:09 PM
  • Single static class instance? What would that be? Can you please elaborate it a bit more...

    thx in advance


    Mitja
    Thursday, July 28, 2011 2:09 PM
  • A brief on when to use "static classes"

    http://msdn.microsoft.com/en-us/library/79b3xss3%28v=vs.80%29.aspx


    John Grove, MCC - Senior Software Engineer
    Thursday, July 28, 2011 2:12 PM
  • I have 300 methods in web service, I try to access with web service proxy class instance like this

     

    public class webCommon

    {

    public static WebService.WebService objservice=new WebService.WebService();

    }

    Button1_click

    MessageBox.Show(webCommon.objservice.getCustomerList());

     

     

     

     

     


    Happy Coding, RDRaja
    Thursday, July 28, 2011 2:14 PM
  • No.  It would be like using many static classes with one method.
    Thursday, July 28, 2011 3:49 PM
  • Exactly~


    Regards, Ted
    Thursday, July 28, 2011 5:02 PM
  • Is there any performance issue of using Single Static Class Instance with large amount of methods??

    Nope, no issues.

    Nit-pick: When you say "Instance" so close to the word "Class" people will think you mean "object", which doesn't make sense if the class is static.  So just say, "a static class with many methods".

    Thursday, July 28, 2011 6:54 PM
  • Method calls are resolved at the compile time, except for virtual methods in unsealed classes. So how many virtual methods are there?

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Friday, July 29, 2011 3:01 AM
  • Hi Sheng,

    I have a Web Service with nearly 400 webmethods,I am using the following code to access the webservice.it was realy slow at start up.

     

    public class webCommon

    {

    public static WebService.WebService objservice=new WebService.WebService();

    }

    Button1_click

    MessageBox.Show(webCommon.objservice.getCustomerList());

     


    Happy Coding, RDRaja
    Friday, July 29, 2011 4:32 AM
  • There are other cost involved, such as generating and JIT an XML serialization assembly for the web service proxy that depends on the class size. There are other one-time initialization involved such as detecting IE's network settings.

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    • Proposed as answer by JohnGrove Friday, July 29, 2011 7:17 PM
    • Marked as answer by Cookie Luo Tuesday, August 2, 2011 2:07 AM
    Friday, July 29, 2011 4:13 PM
  • Can you give any reference for IE's Network Setting which will improve the web service performance??
    Happy Coding, RDRaja
    Saturday, July 30, 2011 2:09 AM
  • An easy test to find the asp.net response time is to use WebClient to download the asmx page and compare with the time used by a web service call. If the bottleneck is at network layer (e.g. SSL certificate revocation check, IE proxy) then the WebClient response time would be slow too.



    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    Saturday, July 30, 2011 3:10 PM