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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:52:39+00:00 2026-05-14T22:52:39+00:00

I’ve got a method in C# that needs to return a very large array

  • 0

I’ve got a method in C# that needs to return a very large array (or any other large data structure for that matter).

Is there a performance gain in using a ref or out parameter instead of the standard return value?

I.E. is there any performance or other gain in using

void function(sometype input, ref largearray)

over

largearray function(sometype input)
  • 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-14T22:52:40+00:00Added an answer on May 14, 2026 at 10:52 pm

    The amount of stack space used on a 32-bit x86 processor to pass arguments of various types:

    • byte: 4 bytes
    • bool: 4 bytes
    • enum: 4 bytes
    • char: 4 bytes
    • short: 4 bytes
    • int: 4 bytes
    • long: 8 bytes
    • float: 4 bytes
    • double: 8 bytes
    • decimal: 16 bytes
    • struct: runtime size of the structure

    • string: 4 bytes
    • array: 4 bytes
    • object: 4 bytes
    • interface: 4 bytes
    • pointer: 4 bytes
    • class instance: 4 bytes

    The ones below the line are reference types, their size will double on a 64-bit processor.

    For a static method call, the first 2 arguments that are up to 4 bytes will be passed through CPU registers, not the stack. For an instance method call only one argument will be passed through registers. The rest are passed on the stack. A 64-bit processor supports passing 4 arguments through registers.

    As is clear from the list, the only time you should ever consider passing an argument by ref is for structures. The normal guidance for this is to do so when the structure is larger than 16 bytes. It isn’t always easy to guess the runtime size of a structure, up to 4 fields would usually be accurate. Less if those fields are double, long or decimal. This guidance then usually recommends turning your structure into a class, precisely for this reason.

    Also note that there is no savings passing an argument as a byte or short intentionally, an int is the type that a 32-bit processor is happy with. Same for currently available 64-bit processors.


    A method return value, the real topic of your question are almost always returned in a CPU register. Most types fit comfortably in the eax or edx:eax registers, an FPU register for floating point values. The only exceptions are large structures and decimal, they are too large to fit a register. They are called by reserving space on the stack for the return value and passing a 4 byte pointer to that space as an argument to the method.

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

Sidebar

Ask A Question

Stats

  • Questions 392k
  • Answers 392k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer during my development in android I've missed a function that… May 15, 2026 at 1:48 am
  • Editorial Team
    Editorial Team added an answer Assuming your image code is in chart2.php, you embed it… May 15, 2026 at 1:48 am
  • Editorial Team
    Editorial Team added an answer Hope this helps: Code Samples on Windows Workflow Foundation (WF)… May 15, 2026 at 1:48 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.