Re: Boxing

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Sijin Joseph (sijinNOSPAMdotnet_at_hotmail.com)
Date: 09/03/04


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);
>



Relevant Pages

  • Re: unsigned short addition/subtraction overflow
    ... unsigned short widens to either ... unsigned int or signed int. ... turns out to be *more* surprising. ... >with unsigned types, but it's possible for unsigned types that are ...
    (comp.lang.c)
  • Re: Expressions in C#...
    ... it is not surprising after all. ... Yep, I really mean 1000 elements of doubles, 999 elements end on the ... allocation path was chosen for double types array, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Segmentation fault - interesting problem with array
    ... > My source code is, ... > int i; ... After this it is giving Segmentation fault. ... It's not surprising that an implementation would impose a limit on the ...
    (comp.lang.c)
  • Re: peculiar problem with expression evaluation
    ... I observed something surprising: ... Here is code snippet ... int i = 5; ... Please see the scores of previous postings about this form of undefined ...
    (comp.lang.c)
  • Re: Boxing
    ... > Although i am sure that internally no boxing takes place in this case, ... > but surprisingly the compiler does generate the box instruction. ... There's nothing surprising about a box happening here - adding an int ...
    (microsoft.public.dotnet.general)