Jump to content

Why don't we use smart pointer in systemc-2.3.x?

Recommended Posts

For many years, SystemC used C++98/03. The latest version of the standard (2023) moves to C++17. So I expect to see more smart pointers (esp. unique_ptr<T>).

There are certainly practitioners already using smart pointers in their code; however, example code usually constrained itself to the pre-C++11 standard.

I suggest using the make_unique<T>() and make_shared<T>() methods because they have some extra safety over using new.

Be careful to use the right type of smart pointer to avoid unnecessary overhead. I suggest you read the C++ Core Guidelines.

Important: You will need the SystemC library to be compiled for the C++ version you use. I suggest building the modern way with cmake.

Link to comment
Share on other sites

  • Allen yang changed the title to Why don't we use smart pointer in systemc-2.3.x?
  • 2 weeks later...

Good point. I don't know that there are any plans currently. Probably needs to be suggested. Both unique_ptr and shared_ptr overloads would be good. 

You could of course extend the class and add your overload.

Caution: if used in bridges or adapters, there may be additional considerations. So you need to be careful to consider the expanded situation.

You may want to consider for what situations you wish to do this. Many use cases simply don't warrant smart pointers because the data is persistent or static.


Link to comment
Share on other sites

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.

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...