Export (0) Print
Expand All

4.5.3 __gc and __nogc Keywords and Arrays

Visual Studio .NET 2003

The keywords __gc and __nogc can be applied to arrays whose element type is a C++ primitive type or the corresponding runtime __value type (Section 5.1).

Example

// __gc_arrays4.cpp
// compile with: /clr
#using <mscorlib.dll>
using namespace System;

int main() {
   int ia1 __gc[] = new int __gc[100];   // __gc array
   Int32 ia2 __nogc[100];   // __nogc array
};

Constraints

  • A __nogc array declared in a __gc or __value class shall use the __nogc keyword.

Example

// __gc_arrays5.cpp
// compile with: /clr
#using <mscorlib.dll>

__gc class G {
   char a[10];   // C2697 did not specify __gc or __nogc
   char b __nogc[10];   // ok
};
  • __nogc new shall not be used to allocate memory for a __gc array.
  • __gc new shall not be used to allocate memory for a __nogc array.
Show:
© 2014 Microsoft