Arrays are generated with one abstract class and one templated class.

The abstract class System::Array maps to .NET System.Array, the templated class System::ArrayG deriving from System::Array represents the concrete array implementation.
So by definition the concrete implementation is a System.Array like with .NET.

Example of C# code:

int[] Foo(int a, int b, int c)
    int[] abc = new int[3];

    abc[0] = a;
    abc[1] = b;
    abc[2] = c;

    int j = abc[0] + abc[1] + abc[2];
    Debug.Assert(j == (a + b + c));

    abc[0] += abc[1] - abc[2];
    Debug.Assert(abc[0] == (a + b - c));

    return (abc);

Will generate this C++ code:

::System::Array__G< ::System::Int32 > * CrossNetUnitTest::Array::TestArray::Foo(::System::Int32 a, ::System::Int32 b, ::System::Int32 c)
    ::System::Int32 __temp164__[] = {     a, b, c
    ::System::Array__G< ::System::Int32 > * numArray = ::System::Array__G< ::System::Int32 >::__Create__(3, __temp164__);
    ::System::Int32 num = (((numArray->Item(0) + numArray->Item(1))) + numArray->Item(2));
    ::System::Diagnostics::Debug::Assert((num == ((((a + b)) + c))));
    numArray->Item(0) = (numArray->Item(0) + ((numArray->Item(1) - numArray->Item(2))));
    ::System::Diagnostics::Debug::Assert((numArray->Item(0) == ((((a + b)) - c))));
    return (numArray);

As you can see, ArrayG constructor can be initialized with a C array. If there is a 0 in the initialization list, the .NET bytecode will actually be different and initialize each member one by one (which depending of the number of zero can bloat the code and slower.
Item(int index) is used to set or get one of the value of the array.

Last edited Sep 7, 2007 at 9:19 PM by OlivierNallet, version 1


No comments yet.