Xesium Posted February 16, 2021 Report Share Posted February 16, 2021 Hi, I have a complicated logger which uses sc_time().value() to print the value of the time. Currently everything is printed in ps resolution. My system at best runs in ms resolution. I want to change the time resolution using sc_set_time_resolution. So I put sc_set_time_resolution(1,sc_core::SC_MS); as the very first line in my sc_main(argc, argv). However the model fails in run-time due to "sc_time object(s) constructed". I'm not quite sure how on the very first line of sc_main() a sc_time object has been created. Any insight is very much appreciated. Also if my approach is incorrect in the first place, please let me know. Quote Link to comment Share on other sites More sharing options...
maehne Posted February 17, 2021 Report Share Posted February 17, 2021 Maybe your application or one of the libraries it is using creates sc_time objects by initialising some global or static constants/variables? Quote Link to comment Share on other sites More sharing options...
Xesium Posted February 17, 2021 Author Report Share Posted February 17, 2021 Very good point. If that's the case (which probably is), is there any way to ever setting time resolution? I knew the compiler would take space for global/static variables and will zero out that piece of memory. Didn't think constructors for those objects will be called prior to sc_main execution! Trying a piece of code and sounds like that's the case. So back to my question, how can I ever set the time resolution assuming that I can't change the current structure of the code? Quote Link to comment Share on other sites More sharing options...
Xesium Posted February 17, 2021 Author Report Share Posted February 17, 2021 Actually I found the answer to my question here: https://stackoverflow.com/questions/19227664/whats-the-c-idiom-equivalent-to-the-java-static-block There is a notion of static block that runs prior to all static variables' initializations. This helped solve the issue as I used the static block to set the time resolution. Quote Link to comment Share on other sites More sharing options...
Eyck Posted February 20, 2021 Report Share Posted February 20, 2021 If you can avoid global variables at all cost. They will bite you more than you think. If you need to have static global variables (e.g. for loggers or memory managers) use the Meyers-SIngleton. Those will be initialized upon first use which usually gives you some control over the life cycle. Another example can be found here: https://github.com/Minres/SystemC-Components/blob/master/incl/tlm/tlm_mm.h Xesium 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.