Jump to content

Dynamically allocating modules.


rafaelkioji

Recommended Posts

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

Link to comment
Share on other sites

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

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.

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