Skip to content

Latest commit

 

History

History
31 lines (17 loc) · 1.51 KB

iii.4.20-newarr.md

File metadata and controls

31 lines (17 loc) · 1.51 KB

III.4.20 newarr – create a zero-based, one-dimensional array

Format Assembly Format Description
8D <T> newarr etype Create a new array with elements of type etype.

Stack Transition:

…, numElems → …, array

Description:

The newarr instruction pushes a reference to a new zero-based, one-dimensional array whose elements are of type etype, a metadata token (a typeref, typedef or typespec; see Partition II). numElems (of type native int or int32) specifies the number of elements in the array. Valid array indexes are 0 ≤ index < numElems. The elements of an array can be any type, including value types.

Zero-based, one-dimensional arrays of numbers are created using a metadata token referencing the appropriate value type (System.Int32, etc.). Elements of the array are initialized to 0 of the appropriate type.

One-dimensional arrays that aren't zero-based and multidimensional arrays are created using newobj rather than newarr. More commonly, they are created using the methods of System.Array class in the Base Framework.

Exceptions:

System.OutOfMemoryException is thrown if there is insufficient memory to satisfy the request.

System.OverflowException is thrown if numElems is < 0

Correctness:

Correct CIL ensures that etype is a valid typeref, typedef or typespec token.

Verifiability:

numElems shall be of type native int or int32.