Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5991079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:20:09+00:00 2026-05-22T23:20:09+00:00

Quick question: If I have a very large function/sub in a class that is

  • 0

Quick question: If I have a very large function/sub in a class that is an instance method (i.e., not Shared), do I gain or lose anything by moving that to a shared method and then declaring a small stub method for the instance use?

I.e., I go from this:

Public Sub MyBigMethod(ByVal Foobar As String)
    If String.IsNullOrWhitespace(Foobar) Then
        Throw New ArgumentNullException("Foobar")
    End If

    ' Lots and lots of ugly code.
    ' Really.  There is lots of ugly code here.
    '
    ' Lorem ipsum dolor sit amet, consectetur adipiscing
    ' elit. Aliquam vel erat sit amet massa ultricies
    ' adipiscing. Mauris eu est ligula, a pharetra lorem.
End Sub

To This:

Private Shared Sub MyBigMethod(ByVal Obj as MyObj, ByVal Foobar As String)
    ' Lots and lots of ugly code.
    ' Really.  There is lots of ugly code here.
    '
    ' Lorem ipsum dolor sit amet, consectetur adipiscing
    ' elit. Aliquam vel erat sit amet massa ultricies
    ' adipiscing. Mauris eu est ligula, a pharetra lorem.
End Sub

Public Sub MyBigMethod(ByVal Foobar As String)
    If String.IsNullOrWhitespace(Foobar) Then
        Throw New ArgumentNullException("Foobar")
    End If

    Call MyClass.MyBigMethod(Me, Foobar)
End Sub

My thinking is I save on memory size per each instance of the object. Because each instance only has to lug around the stub method which handles calling the shared version and passing an instance of itself to the shared method so that it can do whatever it needs to do. But I’ll wager that I sacrifice a very teensy amount of speed because of the added function call overhead.

Correct?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:20:10+00:00Added an answer on May 22, 2026 at 11:20 pm

    My thinking is I save on memory size per each instance of the object.

    This is incorrect, because each instance does not store the method in memory. Instance methods are only stored in memory once. Function instructions are different than class members (which are stored per instance).

    Furthermore, you gain a bit of a penalty by adding a function call, because the state of the stub method must be saved when calling the shared method. Then, it has to be loaded back when the shared method terminates. (Note: This is the same penalty you take when making any non-inline function call; the penalty becomes more stiff as the quantity and size of parameters increase)

    You went down a logical line of thinking, but it was based upon the assumption that each instance gets its own logic instructions — when they are actually used across all instances of a class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick question: I have a very busy form going on that I have developed
Quick question. What do you think, I have a few sites that use a
Quick question. There is a legacy website (that is not under my control and
I have a quick question about fetching results from a weakly typed cursor and
just a quick question: I am a CS undergrad and have only had experience
just a quick question, if I have a matrix has n rows and m
Quick question (I hope), how do I include a window 6 class library dll
Quick one; am I right in thinking that passing a string to a method
I have a class that has to take product information from one system's database
Quick question: Would it be a good or a bad idea to implement my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.