Jump to content

Dynamically allocating modules.

Recommended Posts



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

Share this post

Link to post
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


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now