Jump to content

Recommended Posts

Posted

A *item = A::type_id::create("item", this);

I am curious about the difference from systemverilog? should I delete item by myself,  or will uvm systemc lib totally take over it?

Posted

You need to take care yourself as the factory just calls new and returns a raw pointer. You should use a std::unique_ptr to hold the raw pointer:

#include <memory>

std::unique_ptr<A> a{A::type_id::create("item", this)}; 

or if you have to keep declaration and initialization separate:
 

#include <memory>

std::unique_ptr<A> a;
a.reset(A::type_id::create("item", this)); 

This way C++ takes care of destruction properly

Posted

your reply is very helpful.

 

1 hour ago, Eyck said:

You need to take care yourself as the factory just calls new and returns a raw pointer. You should use a std::unique_ptr to hold the raw pointer:

#include <memory>

std::unique_ptr<A> a{A::type_id::create("item", this)}; 

or if you have to keep declaration and initialization separate:
 

#include <memory>

std::unique_ptr<A> a;
a.reset(A::type_id::create("item", this)); 

This way C++ takes care of destruction properly

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...