Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 7th, 2006, 06:01 AM
Authorized User
 
Join Date: Jun 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ratheesh_param
Default Advanced Details of Boxing?

Hi everybody

     Can anyone give me detailed idea about the Boxing? I mean when it convert from value to object , does it completly remove from stack and store it into heap?

Thanks in advance

Ratheesh

 
Old November 7th, 2006, 11:04 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

 
Quote:
quote:...does it completly remove from stack and store it into
Quote:
heap?
Nope. The unboxed version remains on the stack and can be reused. Here's the blow-by-blow:

Code:
static void Main() {
        Int32 v = 1;        // Allocate on stack.
        Object o = v;        // Box the value type (now a reference
                                // type). The address of the new
                                // reference type is returned from the
                                // heap and stored in o.

        // v now has two seperate representations. A boxed form on the heap,
      // and an unboxed form on the stack. The boxed form will be garbage
        // collected. The unboxed form can be reused (the Object variable doesn't
        // know it exists), and will be freed when this method terminates.
        // The lifetime of the boxed form extends beyond the lifetime of the
        // unboxed form.

        v = 2;                // Change the value of the unboxed form on the 
                                // stack.            
    }

Here's the generated IL:

Code:
.method private hidebysig static void  Main() cil managed
{
  .entrypoint
  // Code size       12 (0xc)
  .maxstack  1
  .locals init ([0] int32 v,
           [1] object o)

  // Allocate value type on stack
  IL_0000:  ldc.i4.1
  IL_0001:  stloc.0

  // Box value type and store the reference
  // pointer to the new reference type on the
  // heap in the object variable.  
  IL_0002:  ldloc.0
  IL_0003:  box        [mscorlib]System.Int32
  IL_0008:  stloc.1

  // Change the value of the value type
  // on the stack.
  IL_0009:  ldc.i4.2
  IL_000a:  stloc.0
  IL_000b:  ret
} // end of method Program::Main
HTH,

Bob

 
Old November 8th, 2006, 03:16 AM
Authorized User
 
Join Date: Jun 2006
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to ratheesh_param
Default

Thank u very much BOB






Similar Threads
Thread Thread Starter Forum Replies Last Post
Where is Advanced Search ? MikeW2 BOOK: Beginning SharePoint 2007: Building Team Solutions with MOSS 2007 ISBN: 978-0-470-12449-9 2 August 13th, 2007 03:36 AM
Advanced bitmap help UsrNm C++ Programming 1 September 13th, 2004 09:49 AM
Letter Boxing and Crystal Report ask4jm Crystal Reports 0 August 26th, 2004 03:50 AM
Question about boxing Utpal Pro VB.NET 2002/2003 1 June 7th, 2003 02:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.