473,654 Members | 3,264 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Program Crashing From Running Too Fast?

Hi, I'm writing a program using Metrowerks CodeWarrior 4.0 that
determines the best possible combination of a data set by checking
every possible combination. I found there were about 250,000,000
possibilities and decided to insert a cout in the loop that gave the
percentage that had been completed. The program worked, but I soon
realized it would take almost a month of execution time for it to
finish. I figured the cout was slowing the program down so I decided
to make it occur less by mod'ing the program's overall count number
with a large number in an if statement and seeing if it was equal to 0
and putting the cout inside (ie. if (numTries % 10000 == 0) { cout <<
....; }). However, after doing so the program would crash with code
"c0000005" (I later found even using mod 2 would cause it to crash).
I then commented off the if and cout statements, but it still crashed.
When I put the cout statement back by itself it worked fine again. I
then checked with the debugger to see where it was crashing and it
turned out to be a simple addition assignment without overflow. So my
only idea is that the program is running too fast. But due to the
nature of my program, I need it to run as fast as possible. Anyone
know what causes this to happen and how to fix it?

Also, because I would like to be able to pause the program as well as
send various other user-input commands to it without stopping it, is
it possible for a console window to accept keyboard input without
halting execution of the program? I would prefer not to have to alter
the entire program to have it run in a window. Also, is there an
equivalent in CodeWarrior to the clrscr() statement?

Thanks a lot for any help.

Sincerely,
Darien A. Gothia
Jul 22 '05 #1
3 2195
Daragoth wrote:
Hi, I'm writing a program using Metrowerks CodeWarrior 4.0 that
Usually, in this newsgroup it doesn't matter what you use unless
it is a known bug in the compiler that causes your problems (which
in this case it might be).
[...] Anyone
know what causes this to happen and how to fix it?
I've encountered only one situation in my whole career when changing
the code to output something fixed some problem I couldn't otherwise
detect or debug. It was faulty optimization that the C++ compiler
applied and a variable didn't get its value stored. Adding a printf
or a cout statement caused the optimizer to choke on a long sequence
of statements and not "optimize away" storing the correct value in
memory.

Whether you're experiencing the same situation, I don't know. Try
disabling some optimizations and see if the situation changes. Sheer
speed of an algorithm cannot change the outcome of the system if it
is single-threaded.
Also, because I would like to be able to pause the program as well as
send various other user-input commands to it without stopping it, is
it possible for a console window to accept keyboard input without
halting execution of the program? I would prefer not to have to alter
the entire program to have it run in a window. Also, is there an
equivalent in CodeWarrior to the clrscr() statement?


There is nothing of that sort in the Standard C++ language.

Victor
Jul 22 '05 #2
da******@kuriri nmail.com (Daragoth) wrote:
[My program fails when some debugging is added]

However, after doing so the program would crash with code "c0000005"
ISTR this is the Windows code for a segfault.
So my only idea is that the program is running too fast.
Unlikely, to say the least.
Anyone know what causes this to happen and how to fix it?
Most likely, you have a bug in your program elsewhere that causes
memory corruption, and it only shows up under some circumstances.

Post your code (or preferably, the smallest subset of your code
that shows the problem).
Also, because I would like to be able to pause the program as well as
send various other user-input commands to it without stopping it, is
it possible for a console window to accept keyboard input without
halting execution of the program? I would prefer not to have to alter
the entire program to have it run in a window.


You would have to create a background processing thread, or
use a system-specific function that can poll the keyboard
without waiting.
Jul 22 '05 #3
In article <84************ **************@ posting.google. com>,
Old Wolf <ol*****@inspir e.net.nz> wrote:
da******@kurir inmail.com (Daragoth) wrote:

Also, because I would like to be able to pause the program as well as
send various other user-input commands to it without stopping it, is
it possible for a console window to accept keyboard input without
halting execution of the program? I would prefer not to have to alter
the entire program to have it run in a window.


You would have to create a background processing thread, or
use a system-specific function that can poll the keyboard
without waiting.


Also potentially workable, and less unportable, is to install a handler
for the interrupt signal that sets a "user wants to say something" flag,
and periodically check this flag and stop for user input if it's set.

(The user needs to know to say "Okay, get going again now", since the
program will have to suspend normal operation while it's waiting for
user input.)
dave

--
Dave Vandervies dj******@csclub .uwaterloo.ca

You can start a flame war in comp.lang.c just by saying "good morning".
--Richard Heathfield in comp.lang.c
Jul 22 '05 #4

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

Similar topics

4
12240
by: logicalfeline | last post by:
How do you prevent multiple instances of a program from running? Cat
6
3326
by: DC | last post by:
Hi, I am programming a search catalogue with 200000 items (and growing). I am currently using the SQL Server 2000 fulltext engine for this task but it does not fit the requirements anymore. The products typically do have a verbose name, "canadian superapples: red tasty juicy macintosh apple from toronto" and the like. If a customer is looking for "canadian apple" this product needs to match, but also if he is looking for "juicy mac".
3
2764
by: Rob Nicholson | last post by:
How do you determine if a program is running in the Visual Studio IDE/debugger as opposed to standalone? We often include support files in the same folder as the executable and would so something like: Dim SupportFile As String SupportFile = Application.StartupPath & "\SupportFile.txt" But of course this fails when running in the IDE as the executable is in the BIN folder so we need to do something like this:
4
1452
by: vashwath | last post by:
Hi all, I am not able to figure out why the following program fails. Hope this long program does not irritate you. #include <stdlib.h> #include <string.h> #include <stdio.h> #define K_TITLE_LEN 14 #define K_MAX_PLMS_ENTRIES 2000 #define K_SUMMARY_TITLE_LEN 18
0
1009
by: RKhaled | last post by:
Hello, Whenever users close this program by clicking on the x in the top right, the program continues running in the background. Any suggestions on how to close it completely?
2
1565
by: airprince | last post by:
I have a program in visual basic 6. Is it possible that if my program already running, even if I click my program shortcut icon, it will not run again instead it will show the one that is running already. Tnx
9
1583
by: Hypnotik | last post by:
Ok, so I've finished the "library" problem. The program takes in input and sorts the information. However the program crashes if I enter an authors name beginning with the letter z. Also if the book starts with the letter Z the program crashes. Everything else works perfectly.....except for using the letter Z. Any ideas? #include <iostream> #include <ctype.h> using namespace std; struct book
5
1408
by: gobblegob | last post by:
I would like to know some code to check if my program is running, if so then not load. Thanks in advanced, Gobble.
0
1176
by: lotus111 | last post by:
I am using the new visual basic 2008. I want to prevent the program from running twice if the user clicks on it more than once. Is there a setting for this? Or some other method?
0
8379
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8294
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8709
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2719
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1924
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1597
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.