3

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.

Greg
  • 18,111
  • 5
  • 46
  • 68
coderoo
  • 65
  • 5
  • An interesting question. I've never heard of such a thing. I think you're going to have to do it manually. Or perhaps semi-automatically: could you have a thread that checks for null references and calls the destructor when it detects one? – Matthew Taylor May 16 '19 at 07:45

1 Answers1

3

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.

dave_59
  • 39,096
  • 3
  • 24
  • 63