Jump to content

Instantiating N submodules (N is a template parameter)


Recommended Posts

I'll give a brief example of what I intend to to:


template <int N>

   subblock subblock[N];
   void proc();
      unsigned int i;
      for (i = 0; i < N; i++)
         round_robin[N]("subblock instance");
Basically, N subblocks must be instantiated inside request_scheduler and N is a template parameter. The compiler is complaining about the code above. Is it possible to do that?
Link to comment
Share on other sites

Thanks for the answer, using the sc_vector did the trick :)


But how can I use vectors when submodules require extra arguments in the constructor? They tried to cover it in 1666-2011, but they wouldn't be able to write a worst explanation even if they would have put a lot of effort on it. Really tough to understand with incomplete examples.

Link to comment
Share on other sites

I think I can safely say the LRM is not intended to be a tutorial :-)


Philipp Hartmann wrote a paper




and he also wrote the original code.


I'm sure Philipp will pop up if you have any further questions,


kind regards



P.S. I couldn't get the download link to work - but if you click View, you can then download it from the viewer.

Edited by apfitch
Link to comment
Share on other sites

Thanks for letting me know, that the download link is somewhat broken.  I tried to fix it and it seems to be working here now.  The link to the details page is https://complex.offis.de/documents/doc_details/29. In this presentation, several examples for "custom creator functions" are given.  Personally, I prefer the variant of using sc_bind in combination with a local member function:


// creator function (member function of surrounding block)
request_scheduler_m::create_subblock( const char* nm, size_t idx ) {
  // call constructor with other parameters
  subblock* sub_p = new subblock(nm, param_1, param_2);
  return sub_p;

// initialize vector with custom creator
subblock_vec.init( N, sc_bind( &request_scheduler_m::create_subblock, this, sc_unnamed::_1, sc_unnamed::_2 ) );


Using this variant of a creator, you can easily "store" and/or prepare the values of the module parameters within member variables of the surrounding module.


Greetings from Oldenburg,

Edited by Philipp A. Hartmann
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...