473,386 Members | 1,828 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,386 software developers and data experts.

Stack Overflow

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 through. When it does, the app
looks to see what kind of data it is, and does something with it, such as
parse the data, write it to a file, ignore it, etc.

The code almost completes when it throws a stack overflow exception. The
code makes no recursive calls. I suspect the data is coming through faster
than the app can process it, and events keep piling up until the stack
overflows. Is that possible? The exception happens at random points - never
the same Sub or Function twice in a row. But it does happen, every time.

The reason I think so is because when I process the data in real time, it
throws an exception. When I just record everything to a file and process it
from a file later instead of live, with the same code, no problem at all. The
problem is, I need the results in more or less real time, not later.

If it could be that the events are piling up too fast, it's not critical
that I process every single piece of data that comes through - there are
natural breakpoints in my code where, if it's possible, I would be willing to
clear all pending events. Can that be done? Is it a reasonable approach?

Thanks!

Eric
Sep 1 '06 #1
9 4109
Hello, Eric!

EWThe code almost completes when it throws a stack overflow exception.
EWThe code makes no recursive calls. I suspect the data is coming through
EWfaster than the app can process it, and events keep piling up until the
EWstack overflows. Is that possible?

If I understand correctly data is stored in the buffer.
Then taken from that buffer and processed, right?

Then data is piling up in the heap not in the stack...

Can you provide code sample where you process data?
When exception occured - did you look at callstack?

--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Sep 1 '06 #2
Eric Webster wrote:
The code almost completes when it throws a stack overflow exception. The
code makes no recursive calls. I suspect the data is coming through faster
than the app can process it, and events keep piling up until the stack
overflows. Is that possible? The exception happens at random points - never
the same Sub or Function twice in a row. But it does happen, every time.
Is it possible that your processing code is triggering another event.
For example, if you changed the value of a TextBox within the
TextChanged event of that textbox. Could something like that be
happening?

If the code were in the middle of the event, performing processing, I
don't think the event could be re-entered unless you are calling
DoEvents or something to cause events to be processed.

Perhaps you could, in the event code, take the data and place it into a
queue and then have a dedicated thread that processes the data in the
queue.

Sep 1 '06 #3
Perhaps you could, in the event code, take the data and place it into a
queue and then have a dedicated thread that processes the data in the
queue.
That's a thought - a bit outside my experience ini VB, but worth the stretch
to learn it.

I was calling DoEvents in a number of places, but recently took out all
DoEvents calls to see if that made a difference.

It's also interesting that the code gets slower and slower as it runs. What
it's listening to is stock market data, trades in real time. The first 500
stock tickers happen inside a minute. The next 500 takes 2 minutes, the next
in 2.5, and so on, until we get to 10 minutes between updates. So something
is bogging down the system. When I just dump the stream to a file and process
after hours, I can zip through the whole day in seconds. Live, it takes 45 -
60 minutes and the system eventually crashes.

There are multiple events (I can't change the structure of the events,
that's given to me by the Exchanges) firing - one for timestamp messages, one
for summaries, one for company fundamentals, an one event per successful
trade on the Exchanges (NYSE, NASDAQ, and AMEX), which as you may imagine is
quite a lot.

I can't figure out how to get a dump of the stack to see if I have a zillion
nested calls - when it throws the exception, I basically get nothing back
from VS 2005. Is there an easy way to dump the call stack periodically?
Sep 1 '06 #4
If I understand correctly data is stored in the buffer.
Then taken from that buffer and processed, right?

Then data is piling up in the heap not in the stack...
Well, kind of - events keep firing when data is received and the system just
responds to the "data received" events (there are several). I know it's a
stack exception, unless VS 2005 reports heap boundry errors as stack errors.
Sep 1 '06 #5
My guess is that you are tying events multiple times and not untying them ..

So as the day goes on you pick up linear overhead.

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoung

"Eric Webster" <el*****@nospam.nospamwrote in message
news:D5**********************************@microsof t.com...
>Perhaps you could, in the event code, take the data and place it into a
queue and then have a dedicated thread that processes the data in the
queue.

That's a thought - a bit outside my experience ini VB, but worth the
stretch
to learn it.

I was calling DoEvents in a number of places, but recently took out all
DoEvents calls to see if that made a difference.

It's also interesting that the code gets slower and slower as it runs.
What
it's listening to is stock market data, trades in real time. The first 500
stock tickers happen inside a minute. The next 500 takes 2 minutes, the
next
in 2.5, and so on, until we get to 10 minutes between updates. So
something
is bogging down the system. When I just dump the stream to a file and
process
after hours, I can zip through the whole day in seconds. Live, it takes
45 -
60 minutes and the system eventually crashes.

There are multiple events (I can't change the structure of the events,
that's given to me by the Exchanges) firing - one for timestamp messages,
one
for summaries, one for company fundamentals, an one event per successful
trade on the Exchanges (NYSE, NASDAQ, and AMEX), which as you may imagine
is
quite a lot.

I can't figure out how to get a dump of the stack to see if I have a
zillion
nested calls - when it throws the exception, I basically get nothing back
from VS 2005. Is there an easy way to dump the call stack periodically?

Sep 1 '06 #6
Hi Eric,

I agree with Chris that it is likely that your event handler triggered some
other code which recursively called this event handler again, so an
infinitely calling chain is generated, which causes
StatckOverflowException.

The simplest way to find out the root cause is catching this
StatckOverflowException with a debugger and examine the call stack of this
exception, which will reveal the deep stack root cause clearly.

Normally, when you run your application without debugging, the
StatckOverflowException is thrown, the system will popup a dialog for you
to choose a debugger. You may use a VS2005 instance with source code to
debug this exception. After using the debugger to attach the failure
application, you may open "Call Stack" window from "Debug" menu. Once you
have got the symbol setup correctly, you will get a meaningful call stack
for this StatckOverflowException .

For example, in my test winform application, I used the code snippet below
to simulate the StatckOverflowException:

void RecursionMethod()
{
Console.WriteLine("RecursionMethod");
RecursionMethod();
}

private void button1_Click(object sender, System.EventArgs e)
{
RecursionMethod();
}

When the StatckOverflowException is generated, I choose my source code
debugger in the popup dialog. After the debugger breaks into the
application, I will get the following call stack:

mscorlib.dll!System.IO.TextWriter.WriteLine(string value) Line 448 + 0x3a
bytes C#
mscorlib.dll!SyncTextWriter.WriteLine(string value) Line 711 + 0x1b bytes
C#
mscorlib.dll!System.Console.WriteLine(string value) Line 408 + 0x1e bytes
C#
> StackOverflowTest.exe!StackOverflowTest.Form1.Recu rsionMethod() Line 103
C#
StackOverflowTest.exe!StackOverflowTest.Form1.Recu rsionMethod() Line 104
C#
StackOverflowTest.exe!StackOverflowTest.Form1.Recu rsionMethod() Line 104
C#
StackOverflowTest.exe!StackOverflowTest.Form1.Recu rsionMethod() Line 104
C#
.................................................. ....................

StackOverflowTest.exe!StackOverflowTest.Form1.Recu rsionMethod() Line 104 C#

It is very clear that the root cause of the StatckOverflowException is
generated by recursively calling RecursionMethod.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 4 '06 #7
Hi Eric,

Have you reviewed my reply? Have you got the debugger launch for this
StatckOverflowException and got the call stack regarding it?

If you still need any help please feel free to tell me, I will work with
you. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 7 '06 #8
Jeffrey, thanks for the followup. I did get the call stack function up today,
that did the trick. Seems both our theories were true - in a periodic
summarization sub I had left some debugging messages to be displayed in the
app, so to make sure they painted, I called Application.DoEvents. This opened
the floodgate for more events to come flowing through, which were processed -
until the next period summarization event, in which case the cycle started
over again. Tomorrow I'll leave it run taking out the DoEvents call and I'll
guess that the system will function correctly.

Thanks for your help!

Eric
Sep 7 '06 #9
Hi Eric,

Thank you for sharing the information with us!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 7 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ip4ram | last post by:
I am quite puzzled by the stack overflow which I am encountering.Here is the pseudocode //define stack structure //function operating on stack void my_stack_function( function parameters) {...
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...
19
by: Jim | last post by:
I have spent the past few weeks designing a database for my company. The problem is I have started running into what I believe are stack overflow problems. There are two tab controls on the form...
4
by: Victor | last post by:
Hello, I've got a situation in which the number of (valid) recursive calls I make will cause stack overflow. I can use getrlimit (and setrlimit) to test (and set) my current stack size. ...
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...
2
by: Ali | last post by:
Hi, I got stack overflow errors while using an unmanaged dll from managed c# application. When i use editbin.exe to increase stack size of app , it works. Is there a way to increase stack size of...
6
by: Daz | last post by:
Hi everyone! It is indeed, once again time for me to ask another stupid question. I have been searching around on the net for quite a while, and can't find anything that explains 'exactly'...
24
by: John | last post by:
I know this is a very fundamental question. I am still quite confused if the program call stack stack should always grows upwards from the bottom, or the opposite, or doesn't matter?? That means...
7
by: amit.atray | last post by:
Environement : Sun OS + gnu tools + sun studio (dbx etc) having some Old C-Code (ansi + KR Style) and code inspection shows some big size variable (auto) allocated (on stack) say for ex. char...
87
by: CJ | last post by:
Hello: We know that C programs are often vulnerable to buffer overflows which overwrite the stack. But my question is: Why does C insist on storing local variables on the stack in the first...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.