// Access members via pointer indirection.
Point point2;
Point* p2 = &point2;
(*p2).x = 100;
(*p2).y = 200;
Console.WriteLine((*p2).ToString());
}
The stackalloc Keyword
In an unsafe context, you may need to declare a local variable that allocates memory directly from
the call stack (and is therefore not subject to .NET garbage collection). To do so, C# provides the
stackalloc keyword, which is the C# equivalent to the _alloca function of the C runtime library.
Here is a simple example:
unsafe static void UnsafeStackAlloc()
{
char* p = stackalloc char[256];
for (int k = 0; k < 256; k++)
p[k] = (char)k;
}
Do'stlaringiz bilan baham: