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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:20:29+00:00 2026-06-05T01:20:29+00:00

Passing one class/struct vs passing several parameters I am wondering about performance considerations. Would

  • 0

Passing one class/struct vs passing several parameters

I am wondering about performance considerations.

Would it be better performance-wise to pass into a method call a class or a struct (which?) holding two int parameters and an object reference, or would it be better to pass these three as three parameters?

Note:
I am developing on the Unity3D platform, so it’s possible some things work differently then the classical .NET

  • 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-06-05T01:20:31+00:00Added an answer on June 5, 2026 at 1:20 am

    If you pass a class, then the first thing you need to do is create an object, which will later need to be garbage collected. Not a problem normally, but on some Unity target platforms that could be undesirable if you are doing this lots.

    If you pass a struct normally, then it needs to copy the struct. If it was big enough for you to be asking questions about encapsulation (i.e. representing more than a few parameters), then it is probably non-trivially big, and could be a pain to copy all the time, especially if passing down a few layers.

    Passing individual parameters is fairly well known, and shouldn’t cause a huge problem. Optional parameters in 4.0 can make adding more parameters less painful, but they are still passed (just with their default values).

    An interesting option for unity is passing a struct by ref, since this doesn’t copy the contents (it just passes a reference to the value you created, typically on the stack), and doesn’t require any garbage collection, i.e.

    var args = new SomeArgs(123, "abc", 23.4F, false); // <=== a struct
    SomeMethod(ref args);
    

    However, in most useful cases, I can’t see that this gains you much over just

    SomeMethod(123, "abc", 23.4F, false);
    

    unless of course you are passing the parameters down a few layers – in which case it has the advantage that it doesn’t need any copying. But watch out: the values are no longer independent between layers in the call-stack (regular parameters, not passed ref, are isolated to the method).

    I think that at least describes some of the things to consider, but I don’t have a conclusive answer for you. If you want something more scientific, you probably need to measure.

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

Sidebar

Related Questions

When passing forward declared struct or a class, one has to pass it to
I'm having trouble passing a variable defined in one class instance to another class
I am passing an NSDictionary object from one view class to another as I
Having some trouble passing values from one class to another. I basically have a
I've been having a problem with passing variables between classes. I have one class
All, I am having difficulty passing a struct to a class constructor. I am
I am having some trouble with passing data of an array from one class
I am passing one parameter/object to the function RefValTest(object oIn) by the value but
Is there a way to recieve the complete nameserver set by passing just one
Objective-C uses a sophisticated message-passing system when one object calls a method on another

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.