Featured post
What's the magic of arrays in C# -
int[] = new int[5]; string[] b = new string[1];
the types of both a
, b
inherit abstract system.array
, there no real classes in built-in library(it seems there runtime types, can't find type defination class of int[]
). can tell me happens while compiling? , why did they(the c# team) make design(i mean why it's not array<t>
,instead using abstract class compiler magics)?
trying reason out within .net type system doesn't far. there core support built jit compiler , clr deal creating arrays. statement this:
var arr = new int[5];
generates il:
il_0001: ldc.i4.5 il_0002: newarr [mscorlib]system.int32
which jit compiler translate machine code:
00000035 mov edx,5 ; arg2 = array size 0000003a mov ecx,6f535f06h ; arg1 = typeof(int) 0000003f call ffd52128 ; call jit_newarr1(type, size)
core ingredients here dedicated il opcode, newarr, instead of usual newobj opcode creates instance of class. , simple translation clr helper function gets object created. can have look-see @ helper function sscli20 source code, clr\src\vm\jithelpers.cpp
. large post here, heavily optimized make kind of code run fast possible, having direct access type internals available clr code.
there 2 of these helpers available, jit_newarr1() creates one-dimensional (vector) arrays , jit_newmdarr() creates multi-dimensional arrays. compare 2 overloads available type.makearraytype().
- Get link
- X
- Other Apps
Comments
Post a Comment