Re: Boxing
From: Sijin Joseph (sijinNOSPAMdotnet_at_hotmail.com)
Date: 09/03/04
- Next message: M O J O: "Scaling problem - font size"
- Previous message: Gary Chang: "RE: Unique Identifier for a machine"
- In reply to: Jon Skeet [C# MVP]: "Re: Boxing"
- Next in thread: Jon Skeet [C# MVP]: "Re: Boxing"
- Reply: Jon Skeet [C# MVP]: "Re: Boxing"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 03 Sep 2004 11:22:52 +0530
Well it's surprising because 't.a' is already on the heap, since it is
part of a reference type. What would be intresting is to see if the
boxing is actually taking place, although the box instruction is being
generated, is the JITer is actually creating a new object on the heap to
store the value. It would be intresting to look at the rotor sources to
check the same.
Sijin Joseph
http://www.indiangeek.net
http://weblogs.asp.net/sjoseph
Jon Skeet [C# MVP] wrote:
> Sijin Joseph <sijinNOSPAMdotnet@hotmail.com> wrote:
>
>>Although i am sure that internally no boxing takes place in this case,
>>but surprisingly the compiler does generate the box instruction.
>>
>>I compiles this code
>>
>> class Class1
>> {
>> /// <summary>
>> /// The main entry point for the application.
>> /// </summary>
>> [STAThread]
>> static void Main(string[] args)
>> {
>> Test t = new Test();
>> ArrayList al = new ArrayList();
>> al.Add(t.a);
>> }
>> }
>>
>> public class Test
>> {
>> public int a = 5;
>> }
>
>
> There's nothing surprising about a box happening here - adding an int
> to an ArrayList will always box, as it's got to store it in an object
> for the ArrayList to work. (Note that ArrayList.Add takes object, not
> int.)
>
> You'll see the same thing if you just try
>
> al.Add(5);
>
- Next message: M O J O: "Scaling problem - font size"
- Previous message: Gary Chang: "RE: Unique Identifier for a machine"
- In reply to: Jon Skeet [C# MVP]: "Re: Boxing"
- Next in thread: Jon Skeet [C# MVP]: "Re: Boxing"
- Reply: Jon Skeet [C# MVP]: "Re: Boxing"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|