How to increase stack size in Bloodshed Dev-C++?

你离开我真会死。 提交于 2019-12-12 03:11:16

问题


We are using Blodshed Dev-C++ to in an image processing project. We are implementing connected component labelling on a video frame. We have to use a recursive function which recurses so many times that we get a stackoverflow. How can we have a larger stack size? Is it possible to change it through some linker parameters or anything similar?

void componentLabel(int i,int j,IplImage *img){
  //   blueFrame = img->imageData[i*3*width+j*3];
//     greenFrame = img->imageData[i*3*width+j*3+1];
//     redFrame = img->imageData[i*3*width+j*3+2];

     if(!( img->imageData[i*3*width+j*3]==0 && img->imageData[i*3*width+j*3+1]==0 && img->imageData[i*3*width+j*3+2]==0 )  ){
           //printf("iffffff aq\n");
           return;     
     }
     else{
           //printf("else aq  %d\n",sayac_label);                          
               img->imageData[i*3*width+j*3]=1;  

               new_object.pixel_count=new_object.pixel_count+1;
               new_object.total_row=new_object.total_row+i;
               new_object.total_col=new_object.total_col+j;

               if(j<width-1 ){                   
                         componentLabel(i,j+1,img);                         
               }               
               if(j>0 ){                   
                         componentLabel(i,j-1,img);                   
               }             
               if(i<height-1 ){  
                         if(i>new_object.bottom.satir){
                              new_object.bottom.satir=i;
                              new_object.bottom.sutun=j;                                               
                         }

                         componentLabel(i+1,j,img);                         
               }              
               if(i>0 ){ 
                         if(i<new_object.top.satir){
                              new_object.top.satir=i;
                              new_object.top.sutun=j;                                               
                         }                  
                         return componentLabel(i-1,j,img);               
               }      
     }

回答1:


Only one approach will guarantee that you won't run out of stack size - reformulate the algorithm to be tail recursive (and ensure that your compiler is optimizing tail calls - usually an -O3 (or -O2?) optimization flag).

Short of that, have you increased the maximum stack size that the shell will grant your task?

  ulimit -s <maximum stack size>


来源:https://stackoverflow.com/questions/10018207/how-to-increase-stack-size-in-bloodshed-dev-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!