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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:55:20+00:00 2026-05-15T02:55:20+00:00

I this MSDN Magazine article , the author states (emphasis mine): Note that boxing

  • 0

I this MSDN Magazine article, the author states (emphasis mine):

Note that boxing always creates a new
object and copies the unboxed value’s
bits to the object. On the other hand,
unboxing simply returns a pointer to
the data within a boxed object: no
memory copy occurs.
However, it is
commonly the case that your code will
cause the data pointed to by the
unboxed reference to be copied anyway.

I’m confused by the sentence I’ve bolded and the sentence that follows it. From everything else I’ve read, including this MSDN page, I’ve never before heard that unboxing just returns a pointer to the value on the heap. I was under the impression that unboxing would result in you having a variable containing a copy of the value on the stack, just as you began with. After all, if my variable contains “a pointer to the value on the heap”, then I haven’t got a value type, I’ve got a pointer.

Can someone explain what this means? Was the author on crack? (There is at least one other glaring error in the article). And if this is true, what are the cases where “your code will cause the data pointed to by the unboxed reference to be copied anyway”?

I just noticed that the article is nearly 10 years old, so maybe this is something that changed very early on in the life of .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-05-15T02:55:21+00:00Added an answer on May 15, 2026 at 2:55 am

    The article is accurate. It however talks about what really goes on, not what the IL looks like that the compiler generates. After all, a .NET program never executes IL, it executes the machine code that’s generated from the IL by the JIT compiler.

    And the unbox opcode indeed generates code that produces a pointer to the bits on the heap that represents the value type value. The JIT generates a call to a small helper function in the CLR named “JIT_Unbox”. clr\src\vm\jithelpers.cpp if you got the SSCLI20 source code. The Object::GetData() function returns the pointer.

    From there, the value most commonly first gets copied into a CPU register. Which then may get stored somewhere. It doesn’t have to be the stack, it could be a member of a reference type object (the gc heap). Or a static variable (the loader heap). Or it could be pushed on the stack (method call). Or the CPU register could be used as-is when the value is used in an expression.

    While debugging, right-click the editor window and choose “Go To Disassembly” to see the machine code.

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

Sidebar

Related Questions

This MSDN article stated that: processors are free to reorder this code internal static
I've found this MSDN article that explains how to monitor processes and services with
Reading an article called Increase LINQ Query Performance in July's MSDN magazine, the author
From this article http://msdn.microsoft.com/en-us/magazine/dd882520.aspx I wanted to create a list of selected days like
According this MSDN article HttpApplication .EndRequest can be used to close or dispose of
As per this MSDN article: W3C Extended Log File Format (IIS 6.0) It says
I've followed the instructions in this MSDN article: http://msdn.microsoft.com/en-us/library/dd206945.aspx Is it possible to call
I'm building a Windows service and following this MSDN article , but I'm stuck
I have been playing with the demo code from this msdn article by Jeffrey
Some 4 years back, I followed this MSDN article for DateTime usage best practices

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.