Article View: borland.public.csharpbuilder.language.csharp
Article #212Re: About "int" value storage.
From: Kolja
Date: Wed, 21 Jun 2006 11:01
Date: Wed, 21 Jun 2006 11:01
97 lines
4344 bytes
4344 bytes
I disassebled my test example by Reflector and had found that compilator
creates each variable as class object (struct 'int' too). But for common
classes it inserts the "newobj" command despite of there are already created
one object for each object variable. For me it seems that Netframework
squanders the memory.
For example:
class Program
{
class myclass : System.Data.DataSet
{
int k;
}
static void Main(string[] args)
{
int i = 1;
myclass o = new myclass();
Console.WriteLine(i.ToString());
Console.WriteLine(o.GetType().ToString());
}
}
The implementation:
.class nested private auto ansi beforefieldinit myclass
extends [System.Data]System.Data.DataSet
{
.method public hidebysig specialname rtspecialname instance void
.ctor() cil managed
{
}
.field private int32 k
}
.method private hidebysig static void Main(string[] args) cil managed
{
.entrypoint
.maxstack 1
.locals init (
[0] int32 i,
[1] ConsoleApplication1.Program/myclass o)
L_0000: nop
L_0001: ldc.i4.1
L_0002: stloc.0
L_0003: newobj instance void
ConsoleApplication1.Program/myclass::.ctor()
L_0008: stloc.1
L_0009: ldloca.s i
L_000b: call instance string int32::ToString()
L_0010: call void [mscorlib]System.Console::WriteLine(string)
L_0015: nop
L_0016: ldloc.1
L_0017: callvirt instance [mscorlib]System.Type object::GetType()
L_001c: callvirt instance string object::ToString()
L_0021: call void [mscorlib]System.Console::WriteLine(string)
L_0026: nop
L_0027: ret
}
Seems like '.locals init' creates full copies of 'int32' and 'myclass' but
not pointers. I conclude that from how it calls 'i.ToString'.
L_0009: ldloca.s i
L_000b: call instance string int32::ToString()
It uses address of 'i' like if whole object is already created. Can you
confirm am I right?
BTW one more conclusion. Since the address of variable 'i' references the
address of structure 'int i' then the value of variable 'i' is left
nonusable. So I think this value should be the integer number the varialbe
'i' represents. So despite the 'i' is the variable of complex data structure
it values the integer number but not address of the structure 'int i'.
Am I right?
"Marc Rohloff [TeamB]" <"on request"> wrote in message
news:aguodigtf9ee$.dlg@dlg.marcrohloff.com...
> On Tue, 20 Jun 2006 12:09:24 +0400, Kolja wrote:
>
>> Can you elaborate?
>
> Internally (i.e deep down and out of site) the CLI source represents
> an int as a struct with a single field, which to all intents and
> purposes is the same thing (they are the same size and layout and
> could be treated either way).
>
> However the C# compiler (as well as ILASM) hides this fact from you.
> It is either an int (unboxed) or an object that looks just like an
> integer.
>
> If I were you I would forget that it is a struct, it is just an
> internal implementation detail.
>
> --
> Marc Rohloff [TeamB]
> marc rohloff -at- myrealbox -dot- com
Technical Details
Message-ID:
<1150887734.571624@angel.elektra.ru>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<1150727965.330076@angel.elektra.ru> <15m76f8teid2h$.dlg@dlg.marcrohloff.com> <1150790966.862793@angel.elektra.ru> <aguodigtf9ee$.dlg@dlg.marcrohloff.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 1efe35,fe3051f5b35308d7 X-Google-Attributes: gid1efe35,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Kolja" <kolja2003@tizcali.com> Newsgroups: borland.public.csharpbuilder.language.csharp References: <1150727965.330076@angel.elektra.ru> <15m76f8teid2h$.dlg@dlg.marcrohloff.com> <1150790966.862793@angel.elektra.ru> <aguodigtf9ee$.dlg@dlg.marcrohloff.com> Subject: Re: About "int" value storage. Date: Wed, 21 Jun 2006 15:01:40 +0400 Lines: 99 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.3790.2663 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.2663 X-RFC2646: Format=Flowed; Original Organization: Ye 'Ol Disorganized NNTPCache groupie Message-ID: <1150887734.571624@angel.elektra.ru> Cache-Post-Path: angel.elektra.ru!unknown@shsv.mcc.elektra.ru X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 193.125.98.3 X-Trace: newsgroups.borland.com 1150887735 193.125.98.3 (21 Jun 2006 04:02:15 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news4.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail