system-verilogsystem-verilog-dpi

How do I execute SystemVerilog code at garbage collection?


I have a SystemVerilog class that encapsulates a C++ class using a chandle and the DPI. I want to be sure that the C++ class’s destructor is called when the SystemVerilog object is destroyed. As far as I can tell, this is not being done automatically and I have to manually call the C++ destructor through the DPI when I think that I no longer need the instance. Not very elegant.

Is there a way to specify that certain code should be run for a SV class at GC? Similar to a Java finalize method.


Solution

  • There is no construct similar to finalize within SystemVerilog. However, you can register a VPI callback (cbReclaimObj) on the handle. See section 38.36.1 of the 1800-2017 LRM.