I am working with a C DLL which accepts parameters of the form of nested pointed structures. It's simplified C# form is something like this:
struct Point
{
public double X;
public double Y;
}
struct Rectangle
{
public unsafe Point* LowLeft;
public unsafe Point* TopRight;
}
The question arises when I want to instantiate struct Rectangle
. How can I create an instance of Point on the heap and then assign its address to LowLeft
and TopRight
fields?
Some wrong ways:
Using C# new keyword directly is syntactically wrong:
r.LowLeft = new Point();
Using a dummy variable seems to be wrong because it is allocated on the heap and thus is freed when we leave the scope:
var dummy = new Point(); r.LowLeft = @dummy;