Come on, it was just a sample to illustrate the idea. It is obvious enough how to make
it work both on big- and little-endian machines:
.class public explicit value N
{
.field[0] public int16 w
.field[0] public int8 b1
}
.method public static void Exec()
{
.entrypoint
.locals init(valuetype MyVT myvt, string Blob, valuetype N n)
ldloca.s myvt
dup
dup
dup
dup
call instance void MyVT::PrintFields()
ldloca.s n
dup
ldc.i4.1
stfld int16 N::w
ldfld int8 N::b1
brfalse.s BigEndian
ldstr bytearray(01 00 00 00 02 00 00 00 00 00 00 00 03 00
04 00 00 00 05 00 00 00 00 00 00 00 06 00)
br.s Continue
BigEndian:
ldstr bytearray(00 00 00 01 00 00 00 00 00 00 00 02 00 03
00 00 00 04 00 00 00 00 00 00 00 05 00 06)
Continue:
dup
stloc.1
ldc.i4.0
call instance void MyVT::Init(string,int32)
call instance void MyVT::PrintFields()
ldloc.1
sizeof MyVT
call instance void MyVT::Init(string,int32)
call instance void MyVT::PrintFields()
ret
}
And bulk initialization (as opposed to by-field initialization) is more economical not
only if you have many fields, but also if you want to initialize the value type many
times from different segments of the blob.
Thanks,
Serge
-----Original Message-----
From: Paolo Molaro [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 17, 2003 2:51 AM
To: [EMAIL PROTECTED]
Subject: Re: [ADVANCED-DOTNET] Binary data in the #US heap.
On 01/15/03 Serge Lidin wrote:
> One example of using an arbitrary blob is value type initialization. Take a look at
>the following code:
> .class public value sequential MyVT
> {
> .pack 1
> .field public int32 a
> .field public int64 b
> .field public int16 c
> .method public void Init(string Blob,int32 Offset)
> {
> ldarg.0
> ldarg.1
> call instance char[] [mscorlib]System.String::ToCharArray()
> ldc.i4.0
> ldelema [mscorlib]System.Char
> ldarg.2
> add
> sizeof MyVT
> cpblk
> ret
> }
This is also a good way to ensure the program won't work on big-endian
systems and, unless the structure is several hundred bytes big, it's
most certainly slower than doing the initialization with load
constant/store field.
lupus
--
-----------------------------------------------------------------
[EMAIL PROTECTED] debian/rules
[EMAIL PROTECTED] Monkeys do it better
You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.
You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.