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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:35:43+00:00 2026-05-13T09:35:43+00:00

Since structs are value-types, their data is copied when passed into a method as

  • 0

Since structs are value-types, their data is copied when passed into a method as an argument. Example:

int someInt = 7;

DoSomeMethod(someInt); // <-- This is passing the "value" 7.

So far, easy to understand, and you’re probably wondering how my question is valid… so consider the following:

public struct TimmysStructOfGoodness
{
    public int SomeInt1;
    public int SomeInt2;
    public int SomeInt3;
    // ... later that day ...
    public int SomeInt999;
}

and then, with reference to the following code:

TimmysStructOfGoodness someStructOfGoodness = new blah blah blah...

DoSomeMethod(someStructOfGoodness); // <-- **HERE IS WHERE THE QUESTION APPLIES!**

Does the above statement try to allocate several megs of ram to “copy” my value-type (struct)?

If the answer is yes – then when/where is the line between “faster” and “slower”?

If no – then why not? Because what I know of value-types, this should be a problem.

MAJOR DISCLAIMER: I know that this has nothing to do with why you would use a struct verses a class, and I know that I will never make a struct with 999 fields – this is just a question of underlying internals and guts and the like 🙂

  • 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-13T09:35:43+00:00Added an answer on May 13, 2026 at 9:35 am

    (updated, thanks to contributions from other users)

    Unlike class, struct is created on stack. So, it is faster to instantiate (and destroy) a struct than a class.

    Unless (as Adam Robinson pointed out) struct is a class member in which case it is allocated in heap, along with everything else.

    On the other hand, every time you assign a structure or pass it to a function, it gets copied.

    I don’t think there’s a hard limit for a struct size. Thousands of bytes is definitely too much. MSDN says:

    Unless you need reference type
    semantics, a class that is smaller
    than 16 bytes may be more efficiently
    handled by the system as a struct.

    This is – if you need to pass it by reference make it a class, regardless of the size.

    On the second thought, you can still pass struct by reference simply by specifying ref in the function parameter list.

    So, a large struct can actually be ok if you pass it by reference and use as a class member.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use (link update) SendListener to handle sms send event, example:… May 14, 2026 at 1:11 am
  • Editorial Team
    Editorial Team added an answer As bmargulies says in his answer, you can do this… May 14, 2026 at 1:11 am
  • Editorial Team
    Editorial Team added an answer First, turn your symbols into MovieClips. Then create a base… May 14, 2026 at 1:11 am

Related Questions

It's not possible to inherit from a C# struct. It's not obvious to me
It seems to me that, in some ways, Java is where C was a
First let me explain how I currently handle validation, say, for an IPv4 address:
I often take the classes that linq2sql generates and create a simple data-only class
I want to write a C# method that can accept any number. Something like:

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.