Dismiss
There will be a system update on Friday, May 5th, 6 PM ET. You may experience a brief service interruption.
Browse Prior Art Database

Automatic Unboxing of the This Pointer

IP.com Disclosure Number: IPCOM000008793D
Publication Date: 2002-Jul-12
Document File: 3 page(s) / 83K

Publishing Venue

The IP.com Prior Art Database

Abstract

Disclosed is a method that creates a simple two-instruction unboxer which saves memory and improves performance on the VM by reducing the applications memory footprint.

This text was extracted from a Microsoft Word document.
At least one non-text object (such as an image or picture) has been suppressed.
This is the abbreviated version, containing approximately 50% of the total text.

Automatic Unboxing of the ‘This’ Pointer

Disclosed is a method that creates a simple two-instruction unboxer which saves memory and improves performance on the VM by reducing the application’s memory footprint.

Background

The virtual machine defined by Microsoft for the .NET platform, and approved as a set of standards by the ECMA, introduces a concept of a value type.  A value type can be used as a general object (like a class instance in Java) or it can be used as raw sequence of bits (as a struct in C). Consider the following definition of value type in C#:

    struct Point3D {

        public double x;

        public double y;

        public double z;

        public override int GetHashCode() {

            return (int)(x + y + z)

The following is a use of the above value type:

    static int use_ptr(ref Point3D p) {

        return p.GetHashCode();  // A

    }

    static int use_ref(object o) {

        return o.GetHashCode();  // B

    }

                    public static void Main()

                    {

        int i;

        Point3D p;

        i = use_ptr(ref p);

        i = use_ref((object)p);

Figure 1 shows the boxed reference “o”, and an unboxed pointer “ptr”. The CLI specification requires that inside the virtual method of a value type (like Point3D.GetHashCode), the ‘this’ pointer is accessed as an unboxed pointer. However such a method can be called with the ‘this’ argument being either the unboxed pointer (call A in use_ptr) or a boxed reference (call B in use_ref).

In the former case, there is no problem because the types of the actual and formal argument match.  However in the latter case, the actual argument is a boxed reference while the formal argument is an unboxed pointer.

There are several ways of addressing this problem. The naïve implementation creates two copi...