Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
<format type="text/markdown"><![CDATA[

## Remarks
Use the <xref:System.Runtime.CompilerServices.FixedAddressValueTypeAttribute> attribute to mark static value types as pinned upon creation.
Use the <xref:System.Runtime.CompilerServices.FixedAddressValueTypeAttribute> attribute to mark static value type fields as pinned upon creation. This attribute does not apply to primitive value type and enum fields.

This attribute is used by the Microsoft Visual C++ compiler.

Static value type fields are created as boxed objects. This means that their address can change as garbage collection is performed. When you apply this attribute to a static value type, its address remains constant during its lifetime.
The storage for static value type fields might be allocated on the GC heap. This means that their address can change as garbage collection is performed. When you apply this attribute to a static value type field, its address remains constant during its lifetime.

## Examples
The following example illustrates the use of the <xref:System.Runtime.CompilerServices.FixedAddressValueTypeAttribute> attribute to pin a static field in memory. It defines an `Age` structure and initializes two classes that have static fields of type `Age`. The second class applies <xref:System.Runtime.CompilerServices.FixedAddressValueTypeAttribute> to pin the field's address. A number of memory allocations are made before and after these two objects are instantiated and the garbage collector is invoked. The output from the example shows that although the address of the first `Age` field has changed after garbage collection, the address of the field to which <xref:System.Runtime.CompilerServices.FixedAddressValueTypeAttribute> is applied has not.
Expand Down
Loading