Skip to content

Latest commit

 

History

History
15 lines (8 loc) · 1.4 KB

iii.1.8.1.2.2-controlled-mutability-managed-pointers.md

File metadata and controls

15 lines (8 loc) · 1.4 KB

III.1.8.1.2.2 Controlled-mutability managed pointers

The readonly. prefix and unbox instructions can produce what is called a controlled-mutability managed pointer. Unlike ordinary managed pointer types, a controlled-mutability managed pointer is not verifier-assignable-toIII.1.8.1.2.3) ordinary managed pointers; e.g., it cannot be passed as a byref argument to a method. At control flow points, a controlled-mutability managed pointer can be merged with a managed pointer of the same type to yield a controlled-mutability managed pointer.

Controlled-mutability managed pointers can only be used in the following ways:

  1. As the object parameter for an ldfld, ldflda, stfld, call, callvirt, or constrained. callvirt instruction.

  2. As the pointer parameter to a ldind.* or ldobj instruction.

  3. As the source parameter to a cpobj instruction.

All other operations (including stobj, stind.*, initobj, and mkrefany) are invalid.

The pointer is called a controlled-mutability managed pointer because the defining type decides whether the value can be mutated. For value classes that expose no public fields or methods that update the value in place, the pointer is read-only (hence the name of the prefix). In particular, the classes representing primitive types (such as System.Int32) do not expose mutators and thus are read-only.