iherrera Posted November 15, 2012 Report Share Posted November 15, 2012 Hi there, I have created a SC_MODULE that has a member consisting on an array of pointers to another SC_MODULE: SC_MODULE(CLAYER_MEM) { FRAME *pframe[10]; SC_CTOR(CLAYER_MEM); } }; In the SC_CTOR declaration I have tried two different syntax for dynamic allocation, both compiling successfully: 1) Allocation with loop for(uint i=0;i++;i<9) { pframe = new FRAME("frame_"); } (Note: I do not care too much at this point about the name assigned to each instance, as long as it is predictable) 2) Allocation without loop pframe[0] = new FRAME("frame_0"); pframe[1] = new FRAME("frame_1"); pframe[2] = new FRAME("frame_2"); pframe[3] = new FRAME("frame_3"); pframe[4] = new FRAME("frame_4"); pframe[5] = new FRAME("frame_5"); pframe[6] = new FRAME("frame_6"); pframe[7] = new FRAME("frame_7"); pframe[8] = new FRAME("frame_8"); pframe[9] = new FRAME("frame_9"); Obviously I prefer the first one because it is more compact, but I have notice that in RUTIME: 1) with loop, I do not see on screen the result of FRAME constructor calls 2) without loop, I clearly see on screen that FRAME constructor is called for every instance Therefore I assume that the loop construction is wrong, but could you please explain to me why? Thankyou in advance. Annossyenudge 1 Quote Link to comment Share on other sites More sharing options...
dakupoto Posted November 15, 2012 Report Share Posted November 15, 2012 Hello, There is something confusing about your code. Could we assume that somewhere in your module, you declare/define 'pframe' as pointer to an array of pointers to 10 FRAME objects. Please note that in the loop, you have: pframe = new FRAME("frame_"); But in the loop unrolling, you have: pframe[0] = new FRAME("frame_0"); .... .... pframe[9] = new FRAME("frame_9"); I am sure you note the difference. Hope that helps. Quote Link to comment Share on other sites More sharing options...
apfitch Posted November 15, 2012 Report Share Posted November 15, 2012 Your loop is wrong, it should be for (unsigned int i = 0; i< 10; i++) (you've got the i<10 and i++ back to front) regards Alan P.S. You can use sc_gen_unique_name("frame") to create unique names Even better, use the new sc_vector classes in SystemC 2.3.0 for creating arrays of modules. maehne 1 Quote Link to comment Share on other sites More sharing options...
iherrera Posted November 15, 2012 Author Report Share Posted November 15, 2012 Thankyou for catching it, the for loop syntax was the bug...(suprisingly compiles correctly!) I have followed your suggestion, and with sc_vector the code is nice and compact: sc_vector< FRAME > frames; Then in the parent module constructor, simply: ... : sc_module(nm) , frame("frame") ... frame.init(10); However I have a new issue now, as I need a higher number of instances. I have searched for the limit, and above 8000 instances the simulation breaks: E549 uncaught exception: std::bad_alloc I guess it depends on the size of the child module and on the host memory capacity, but I just wonder if there is any hard-coded limit in the number of child modules one can instantiate with sc_vector. Could you please let me know? Thanks. Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted November 15, 2012 Report Share Posted November 15, 2012 I guess it depends on the size of the child module and on the host memory capacity, but I just wonder if there is any hard-coded limit in the number of child modules one can instantiate with sc_vector. There is no fixed limit on the size of sc_vector instances, as they are using a std::vector of pointers internally, which has now hard-coded limit either. Apart from the size of the FRAME module itself (in terms of members, etc), you need to consider the required stack allocations for any SC_THREAD processes in the modules as well. If you really need such high numbers of modules, you should try to use SC_METHOD processes whenever possible. Another option may be to reduce the allocated stack size via the set_stack_size() function. Greetings from Oldenburg, Philipp Quote Link to comment Share on other sites More sharing options...
enchanter Posted April 4, 2014 Report Share Posted April 4, 2014 Do we need to release the memory created by "new" in SystemC? If yes, where is the best place to do it? Quote Link to comment Share on other sites More sharing options...
apfitch Posted April 4, 2014 Report Share Posted April 4, 2014 Just write a destructor and release the memory there (it's only C++). If you dynamically create modules, you can probably get away without releasing the memory as the module structure does not change after elaboration, and will hopefully disappear when the program ends. Alan 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.