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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:08:48+00:00 2026-06-01T22:08:48+00:00

Usally I choose between struct and class not because of memory issues but because

  • 0

Usally I choose between struct and class not because of memory issues but because of semantics of the type. Some of my value types have quite large memory footprint, sometimes too large to copy this data all the time. So I wonder if it is a good idea to pass immutable value objects always by reference? Since the objects are immutable they cannot by modified by methods that accept them by reference. Are there other issues when passing by reference?

  • 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-01T22:08:49+00:00Added an answer on June 1, 2026 at 10:08 pm

    Some of my value types have quite large memory footprint

    That suggests they shouldn’t be value types, from an implementation point of view. From "Design Guidelines for Developing Class Libraries", section "Choosing Between Classes And Structures":

    Do not define a structure unless the type has all of the following characteristics:

    • It logically represents a single value, similar to primitive types (integer, double, and so on).
    • It has an instance size smaller than 16 bytes.
    • It is immutable.
    • It will not have to be boxed frequently.

    It sounds like you should be creating immutable reference types instead. In many ways they end up "feeling" like value objects anyway (think strings) but you won’t need to worry about the efficiency of passing them around.

    "Immutability" for value types is a slightly fluid concept – and it certainly doesn’t mean that using ref is safe:

    // int is immutable, right?
    int x = 5;
    Foo(ref x);
    Console.WriteLine(x); // Eek, prints 6...
    ...
    void Foo(ref int y)
    {
        y = 6;
    }
    

    We’re not changing one part of the value – we’re replacing the whole of the value of x with an entirely different value.

    Immutability is somewhat easier to think about when it comes to reference types – although even then you can have an object which in itself won’t change, but can refer to mutable objects…

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

Sidebar

Related Questions

Usually, I try to set my folders to have permission 775, but some web-hosting
In .Net 2.5 I can usually get an equality comparison (==) between a value
When I design classes and have to choose between inheritance and composition, I usually
In Facebook status update box, when I type @ and start typing and choose
I usually: Choose the needed file. Open it in a tab(t character, by default).
Going to decide where to put some of the initialization code. There seems to
I realise there are numerous questions on here asking about choosing between XNA and
This may be somewhat obscure but I've been happily using Eclipse + Perfoce/P4WSAD for
Are there any compelling performance reasons to choose static linking over dynamic linking or
I have a class with a field that needs to be initialized when 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.