Jump to content

Stack Size Overflow due to recursion


Recommended Posts

Hi 

I have 3 to 4 modules and they have 3 to 4 inputs but to synchronize the timing of inputs as they all have to have specific value only then my THREAD PROCESS should run, I am using value_changed_event inside the THREAD PROCESS of the MODULE by using wait(sig.value_changed_event()). But In some MODULES, I am initializing large arrays and due to this when the value changes then it rerun from the 1st Module to the Last and stops in the mid-way displaying the stack over flow as the exception. What Should be the possible solution for this ? I have Increase the Stack size upto  1Giga but still does not work. Thanks 

Link to post
Share on other sites

Hi @wasim6691,

Here is a small set of questions if you can provide some answers it would be helpful:

  • Can you provide details about the development environment?(Linux/Windows)
  • How are you setting up the stack size?
  • Can you modify your code to use dynamically allocated array just for the sake of modelling?

Regards,

Ameya Vikram Singh

Link to post
Share on other sites

Hi

1) my Development Environment is Windows with Visual Studio 2013 for Desktop

2) In Visual Studio, You have the option in the Linker--- System--- Setting for Stack and Heap Size

3) Yes, This is the only option to use Dynamically Allocated.

 

But Can You suggest me some other option to get out of this Stack over flow Problem. ? Thanks. 

RECURSION: By recursion I mean that If I am sending input from Module-1 to Module-2 and then I am expecting a result from Module-1 to Module-2 (Here in their processes I am using sig.value_changed_event())  and then after getting the result from Module-1, Module-2 send the input to Module-3. 

Link to post
Share on other sites
Quote

But In some MODULES, I am initializing large arrays and due to this when the value changes then it rerun from the 1st Module to the Last and stops in the mid-way displaying the stack over flow as the exception.

Do not put large arrays on process stack. Put them into Module instead, and allocate module in heap.

Example:

Large array on stack:

SC_MODULE(top) {

SC_CTOR(top){
   SC_THREAD(thread);
}

void thread() {
int large_array[1000000000]; // will be allocated on sc_thread stack
}

};

int sc_main(int , char**) {
   top top_inst{"top_inst"};
   sc_start();
}

 

After refactoring:

SC_MODULE(top) {

SC_CTOR(top){
   SC_THREAD(thread);
   int large_array[1000000000]; // inside module body
}

void thread() {
}

};

int sc_main(int , char**) {
   auto top_inst = std::make_unique<top>{"top_inst"}; // allocated on heap
   sc_start();
}

 

 

 

 

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