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 6915751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:30:51+00:00 2026-05-27T09:30:51+00:00

Recently, I started working on a project where many reference parameters are passed around

  • 0

Recently, I started working on a project where many reference parameters are passed around by reference. I’ve looked into a lot of the code and the majority of these methods could lose the ref parameter. Although the code functions fine, I was wondering what kind of performance hit there might be by double dereferencing every argument rather than just passing the reference by value.

For example, this code:

public void EmptyList(ref List<string> test)
{
    test.Clear();
}

VS this:

public void EmptyList(List<string> test)
{
    test.Clear();
}

EDIT

After reading what Nicholas Carey had to say, I tried the same thing with the code above. This was the resulting assembly:

            EmptyList(ref List<string> test)
00000028  mov         eax,dword ptr [ebp-40h] 
0000002b  mov         ecx,dword ptr [eax] 
0000002d  cmp         dword ptr [ecx],ecx 
0000002f  call        719210C4


            EmptyList(List<string> test)
00000028  mov         ecx,dword ptr [ebp-40h] 
0000002b  cmp         dword ptr [ecx],ecx 
0000002d  call        71920FD4 
  • 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-27T09:30:52+00:00Added an answer on May 27, 2026 at 9:30 am

    The difference calling by explicit reference and calling by implicit reference is the difference between the lea (Load Effective Address) instruction and the mov (‘Move’) instruction.

    AFAIK, on any modern processor, both of these instructions, in the form used, execute in a single clock cycle, so the difference is pretty much moot.

    Here’s the code generated (debug mode) for the call by [explicit] reference:

                FooBar( ref o ) ;
    00000035  lea         ecx,[ebp-40h] 
    00000038  call        FFD0B008 
    0000003d  nop 
    

    And here’s the code generated (debug mode) for the call by [implicit] reference:

                FooBar( o ) ;
    0000003a  mov         ecx,dword ptr [ebp-40h] 
    0000003d  call        FFD3B008 
    00000042  nop 
    

    The code generated for the called method/function is identical in either case.

    Here’s the sample code I used, FWIW:

    class Program
    {
      static void Main( string[] args )
      {
        object o = null ;
        FooBar( ref o ) ;
      }
    
      private static void FooBar( ref object o )
      {
      }
    
    }
    

    IMHO, omit the ref keyword unless it’s actually needed: all it really does is add semantic noise to the equation.

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

Sidebar

Related Questions

I have recently started working on a very large C++ project that, after completing
We recently started working with XML files, after many years of experience with the
Recently we started working with Database project in Visual Studio 2010. I have added
I have a project that I have recently started working on seriously but had
I've recently started working on a project that uses bazaar. I'm attempting to find
I recently started working on a small personal project in Ruby on Rails, and
I have recently started working on some open source project which I found relevant
Recently I started working on a portable version of a project by copying all
I recently just started playing around in PHP and got myself a small project/homework.
I recently started working on a web project which was already in progress; the

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.