rafaelkioji Posted October 11, 2013 Report Share Posted October 11, 2013 Hi, I'm trying to dynamically allocate N instances of a single module type. I'm trying to use the following algorithm: int N = 5; TMyModuleType *(module[N]); std::string moduleName; for( unsigned int i =0; i < N; i++ ) { moduleName = std::string::to_string("module[%d]", i); module[N] = new TMyModuleType(moduleName) } However the module's name is a legacy of sc_module hierarchy (SC_MODULE), which type is sc_module_name and is not compatible with std::string. How should I initialize dynamically allocated modules? I've already tried to use sc_string, but it's not compatible neither. best regards, Rafael Kioji Quote Link to comment Share on other sites More sharing options...
maehne Posted October 11, 2013 Report Share Posted October 11, 2013 A quick fix should be to use the c_str() member function of std::string in the new call. This converts the std::string into \0-terminated C string returned as a const char*, which is convertible to an sc_module_name. If C++ doesn't do it automatically, a static_cast<sc_core::sc_module_name>(moduleName.c_str()) should do the trick. Regarding dynamic allocations of modules in SystemC, please have a look to sc_vector, which has been added to IEEE Std 1666-2011 and is available in SystemC 2.3. Rational and hints for its usage are available on: sc_vector: A flexible container for modules, ports and ... - Eda-Stds.org https://complex.offis.de/documents/doc_details/29-scvector-and-the-ieee-p1666-2011-systemc-standard Quote Link to comment Share on other sites More sharing options...
rafaelkioji Posted October 11, 2013 Author Report Share Posted October 11, 2013 It works!! Very Nice trick!!!!! Thank you very much. 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.