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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:23:23+00:00 2026-06-01T20:23:23+00:00

I’ve been trying to understand this paragraph, but somehow I couldn’t virtualize it in

  • 0

I’ve been trying to understand this paragraph, but somehow I couldn’t virtualize it in my mind, some one please elaborate it little bit:

Unboxing is not the exact opposite of boxing. The unboxing operation
is much less costly than boxing. Unboxing is really just the operation
of obtaining a pointer to the raw value type (data fields) contained
within an object. In effect, the pointer refers to the unboxed portion
in the boxed instance. So, unlike boxing, unboxing doesn’t involve the
copying of any bytes in memory. Having made this important
clarification, it is important to note that an unboxing operation is
typically followed by copying the fields.

Richter, Jeffrey (2010-02-05). CLR via C# (Kindle Locations
4167-4171). OReilly Media – A. Kindle Edition.

  • 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-01T20:23:24+00:00Added an answer on June 1, 2026 at 8:23 pm

    In order to box an int you need to create an object on the heap large enough to hold all of the data that the struct holds. Allocating a new object on the heap means work for the GC to find a spot, and work for the GC to clean it up/move it around during and after its lifetime. These operations, while not super expensive, aren’t cheap either.

    To unbox a value type all you’re doing is de-reference the pointer, so to speak. You simply need to look at the reference (which is what the object you have is) to find the location of the actual values. Looking up a value in memory is very cheap, which is why that paragraph is saying ‘unboxing’ is cheap.

    Update:

    While an unboxed value type will usually be copied to some other location right after being unboxed, that isn’t always the case. Consider the following example:

    public struct MyStruct
    {
      private int value = 42;
      public void Foo()
      {
        Console.WriteLine(value);
      }
    }
    
    static void Main()
    {
      object obj = new MyStruct();
      ((MyStruct)obj).Foo();
    }
    

    The MyStruct is boxed into obj but when it’s unboxed it’s never copied anywhere, a method is simply invoked on it. LIkewise you could pull a property/field out of the struct and copy just that part of it without needing to copy the whole thing. This might look a bit contrived, but it’s still not entirely absurd. That said, as your quote implies, it’s still likely to copy the struct after you unbox it.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has

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.