Skip to content
Discussion options

You must be logged in to vote

Yes, it is correct. To force it to be dynamic you have to declare it as nullable.

So the situation is following. The structure is a dump of memory. And when you declare a local variable it will reside in the stack. When you declare a field inside the structure, it will be placed inside this structure. If it is a normal class - it will be created dynamically

When you call the constructor in the worst case it will create a dynamic object and copy it content into the stack. There is an optimization which allow to call the constructor directly

For example the following code:

struct X
{
   real r;

   inc()
   {
      r += 1.0
   }
}

public program()
{
   X x := new X();

   x.inc();
}

If yo…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant