473,385 Members | 1,353 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Stack Overflow exception ..

Working on discrete event simulator implemented using sorted list, for asunchronous coomunication. As I tried to put more than 10000 value in the loop. its giving me error of stack overflow exception. although I am not recursively calling any function plz help me its very important for me hanging for weeks for this...

using visaul C++ .Net

Expand|Select|Wrap|Line Numbers
  1. #include< math.h>
  2. #include< time.h>
  3. #include<List>
  4. using namespace System;
  5. using namespace System::Collections::Generic;
  6. using namespace System::Linq;
  7. double lambda,MuBro,MuSer,MuClient,Simtime;
  8.  
  9. double Min(double y,double z)
  10.    {
  11.     if(y<z)
  12.         return y;
  13.     else
  14.         return z;
  15.     }
  16.  
  17. double expntl(double x)
  18.     {
  19.       double z,y;     /* Uniform random number from 0 to 1 */
  20.  
  21.       /* Pull a uniform RV (0 < z < 1) */
  22.       do
  23.       {
  24.  
  25.           z = ((double) rand() / RAND_MAX);
  26.       }
  27.       while ((z == 0) || (z == 1));
  28.  
  29.       /* Inversion formula for exonential RV */
  30.       y=(-1/x) * log(z);
  31.       return y;
  32.     }
  33.  
  34. public ref class Example
  35. {
  36. public:
  37.     static void Main()
  38.     {
  39.  
  40.    struct Analys
  41.      {  
  42.        double TBa;
  43.        double TBss;
  44.        double TBsf;
  45.        double Client;
  46.        double WS;
  47.        double TSsf;
  48.       }Ana[20000];
  49.  
  50.         Console::WriteLine("Please Enter the value of lambda-Arrival rate");
  51.         std::cin>>lambda;
  52.         Console::WriteLine("Please Enter the values for Mu for Client");
  53.         std::cin>>MuClient;
  54.         Console::WriteLine("Please Enter the values for Mu for broker");
  55.         std::cin>>MuBro;
  56.         Console::WriteLine("Please Enter the values for Mu for Server");
  57.         std::cin>>MuSer;
  58.      double NormWork[20000];
  59.      for(int i=0;i<20000;i++)
  60.      {
  61.        NormWork[i]=0.0;
  62.      }
  63.   double avgNormWork=0.0;
  64.   int Qbro=0,numDep=0,Qserver=0;     
  65.   double Qsum=0.0,currtime=0.0;
  66.   SortedList<double, String^>^ slist = gcnew SortedList<double, String^>();
  67.  double TW=0.0, Wser=0.0, totalworkdone=0.0;
  68.  double value=0.1;  
  69.   int cursor=0; 
  70.   srand(clock());
  71.   double Wc=0.0; 
  72.   double Time=0,TimDep=0.0;
  73.   double ClientWork=0.0;  
  74.  Time=currtime+expntl(lambda);  
  75.  slist->Add(Time,"ABro");
  76.  int id=0;
  77.  int no=0;
  78.  
  79.  while(id<=20000)//*******this is loop accepting 10000 and giving right answer but wrong as 20000 is being put in it.
  80.   {
  81.     currtime=slist->Keys[cursor];   
  82.     if(slist->Values[cursor]=="ABro")                                                
  83.       {        
  84.         Qbro=Qbro+1;
  85.         Wc=expntl(MuClient);         
  86.         Ana[no].Client=Wc;           
  87.         Ana[no].TBa=currtime;
  88.         no=no+1;
  89.  
  90.         Time=currtime+expntl(lambda);    //schedualing another arrival in the event queue
  91.         slist->Add(Time,"ABro");        
  92.         Time=currtime+value;
  93.         slist->Add(Time,"SSBro");        
  94.        }
  95.     else
  96.        if(slist->Values[cursor]=="SSBro") 
  97.         {
  98.          TimDep=currtime+expntl(MuBro);
  99.          slist->Add(TimDep,"SFBroAser");
  100.          }
  101.        else
  102.           if(slist->Values[cursor]=="SFBroAser")
  103.            {
  104.              Qbro--;
  105.              Qserver= Qserver+1;
  106.              Time=currtime+value;
  107.              slist->Add(Time,"SSSer");            
  108.            }
  109.           else 
  110.              if(slist->Values[cursor]=="SSSer")
  111.               {
  112.                Wser=expntl(MuSer);
  113.                TimDep=currtime+Wser;
  114.                Ana[id].WS=Wser;
  115.                slist->Add(TimDep,"SFSer");               
  116.               }
  117.              else
  118.                if(slist->Values[cursor]=="SFSer")
  119.                {
  120.                 Qserver--;                
  121.                 Ana[id].TSsf=currtime;
  122.                 id=id+1;
  123.                 numDep++;
  124.                 }                
  125.      cursor=cursor+1;
  126.    }
  127.  
  128.  for(int i=0; i<id; i++)
  129.         {
  130.  
  131.          TW=Ana[i].TSsf-Ana[i].TBa;            
  132.          ClientWork=Min(Ana[i].Client,TW);
  133.          NormWork[i]=(ClientWork+Ana[i].WS)/TW;
  134.          totalworkdone=totalworkdone+NormWork[i];       
  135.         }  
  136.   avgNormWork= totalworkdone/(id-1);
  137.   Console::WriteLine("No of messages arrived in the system were {0}", id); 
  138.   Console::WriteLine("the average normalised work is   {0}", avgNormWork);   
  139.   Console::ReadLine(); 
  140.  
  141.  }
  142. };
  143.  
  144. int main(array<System::String ^> ^args)
  145. {
  146.    Example::Main();
  147.     return 0;
  148. }
Apr 10 '11 #1
1 1784
This may be as simple as increasing your stack size. Check out this article: http://support.microsoft.com/kb/315937
Apr 12 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Aguilar, James | last post by:
Hello all, To begin, yes, this -is- a homework assignment. However, it is for my Algorithms class, and my instructor has given us explicit permission to use "expert" groups like newsgroups, so...
1
by: hardieca | last post by:
Hi, I'm developing a program that analyzes all the webpages on my webserver. I've created one class, Filewalker(), with a function that returns the paths of all ASP pages of interest as a...
7
by: Gorge Bush | last post by:
Hi there, all was going well with my first C# project until now as I am getting a Stack Overflow exception. I haven't seen one of those since DOS programming days and back then all you did was up...
2
by: David W. Walker | last post by:
I am attempting to port a C code that runs OK on a number of Linux and Unix machines to Windows XP using Visual Studio C++. I have set the program up as a console application, but when I try to run...
1
by: Lee Greco | last post by:
A third party vendor has provided me a C++ .Net DLL, a .lib and all necessary ..h files, as well as a sample C++ .NET app that uses the DLL. The sample app needs the Stack Reserve Size set to...
5
by: jbix | last post by:
We have a stack overflow happening. We are NOT doing any recusion. We do have an object being created in Global that is being handed the Context (which I assume is specific to the request thread). ...
9
by: Eric Webster | last post by:
I have a fairly simple VB.Net program I'm developing that listens to data coming over the internet and processes it. The data comes in as events - the app is idle until another chunk of data comes...
5
by: samuraign | last post by:
Hi, My C-code is working properly in Cygwin. But when I run the same code in VC++ or LCC, I use to get stack overflow exception during run time. It is not entring into my function from testbench....
1
by: Aled Hughes | last post by:
Hi, I've discovered a stack-overflow crash scenario when using CWinformsDialog to show a managed UserControl as a dialog in MFC8. Basically all you have to do is press ESCape whilst the...
0
by: pawel.kedzior | last post by:
Hi One of the issues which AppDomains are facing is problem of unsecure code execution in a sandbox. One of its aspects are unhandled exceptions thrown inside domains - they should not...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.