Class static methods and static properies initialization and creation

As far as i know, a class’es static method and properties are created and initialized during end of elaboration phase. However i am getting confused with this thing, if a class is created dynamically during run time(which in indeed after elaboration phase), how is it possible to create its methods and properties before class’s own creation.

In reply to 8Blades:

My understanding is that static properties are, as you mentioned, created during elaboration. This makes sense, because you can access them even if you never create an object of the class. When you create an object handle dynamically, you create all the non-static (automatic) properties.

Static methods can be called without an object of the class as well, just like the class properties. Note the static methods can only access other static methods and properties from the class definition. It makes sense though, nothing else exists until you create an object.

In reply to 8Blades:

The code for a class method is always created at elaboration regardless of whether it is static or non-static. Variables declared inside the method get allocated when calling the method in either case.

A static method does not have an implicit this handle to access non-static class properties.

Also, please read this post about the static versus automatic lifetimes.

In reply to dave_59:

Thanks for explanation Bmorris and Dave !! I got the clear picture now :smiling_face:

In reply to dave_59:

Hi Dave,



module Main;

class A;

int a;

function DISP();

$display(" a == %0d ",a);

endfunction

endclass

A a1 , a2 , a3;


initial begin

a1 = new();
a2 = new();
a3 = new();

end

endmodule


Now I would have Memory Allocated for each Property of class A i.e a1.a , a2.a , a3.a

What about Methods of class A ?
Do they have separate Memory for Each Instance Or is the Memory Shared
Does the Same apply to Virtual / Static Methods ?

In reply to Etrx91:

Yes, constructing a class object allocates an instance of all its properties.

I believe the links I gave in the post above explain your next question.

Marking a method as static or virtual has nothing to do with memory allocation.