C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 19th, 2005, 12:55 AM
jjj93421 jjj93421 is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 342 jjj93421 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 2 Days 3 h 34 m
Warnings Level: 10
Number of bans: 1
Reputation Power: 0
Program quits for absolutely no reason

I recently compiled a program on MSVS C++ 2003. Problem that I'm having is that it seems to be quitting after 30 minutes every time. I haven't a clue why it is doing this since it is supposed to run forever or until I close it. I'm thinking that there is either something wrong in my code or maybe my Norton Anti-virus is stopping it because it thinks that it is a virus. I don't know. What reason would a program just stop and not give an error or anything ? It usually stops when it is minimized to the task bar. Could it be something to that ?

I should say that my compiler is a hacked version and has also just quit on me for no reason very similar to how this compiled program is acting. Could that be it ? If so, I'll compile it on something else.

BTW, when it quits, it doesn't give an error message. It just disappears completely.

Last edited by jjj93421 : December 19th, 2005 at 01:01 AM.

Reply With Quote
  #2  
Old December 19th, 2005, 01:43 AM
jjj93421 jjj93421 is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 342 jjj93421 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 2 Days 3 h 34 m
Warnings Level: 10
Number of bans: 1
Reputation Power: 0
I just tried to compile it on MSVS 6.0 and I got 68 errors and also an internal heap limit error so these could be the cause possibly. Strange how MSVS 2003 gave me no errors but 6.0 hated it. How much faster would a program compiled on MSVS 2003 be compared to one compiled on MSVS 6.0 ?

EDIT: nope still happening

Last edited by jjj93421 : December 19th, 2005 at 03:12 AM.

Reply With Quote
  #3  
Old December 19th, 2005, 04:02 AM
TechNoFear TechNoFear is offline
Offensive Member
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2002
Location: in the perfect world
Posts: 610 TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 14 m 19 sec
Reputation Power: 25
Hard to tell with the amount of info supplied.
Could be anything.
Sounds like a memory or resource leak.

While the app is running (not in the debugger) open your Task Manager.
Options -> Add Columns then add 'Virtual Memory' and 'GDI Objects'. Memory should already be there.

Highlight the app in the 'Processes' TAB.
Watch and wait.

If the app is leaking memory the memory used or the GDI object count will increase. You will see some movement as the app works but the values should remain constant.

>>How much faster would a program compiled on MSVS 2003 be compared to one compiled on MSVS 6.0 ?

about this much ->_________<-
__________________
The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

Frank Zappa

Last edited by TechNoFear : December 19th, 2005 at 04:11 AM.

Reply With Quote
  #4  
Old December 20th, 2005, 01:14 AM
jjj93421 jjj93421 is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 342 jjj93421 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 2 Days 3 h 34 m
Warnings Level: 10
Number of bans: 1
Reputation Power: 0
Thanks for your help. I watched the program and Task Manager for about 40 minutes and just as the program quit on me again, Task Manager showed VM usage at about 8000 K and GDI objects at about 9500 . Both the GDI objects and the VM usage increased steadily over time. I guess maybe when the GDI objects hit 10,000 , that is the maximum and it shuts down ? I noticed that none of my other programs came close to that many GDI objects so I guess my programming in this program sucks. Is their an easy way to correct this or do I have to rewrite a majority of my program ? I mean is their a function I can use that will lower my virtual memory and GDI objects so they won't keep increasing.

I think part of my problem is that I'm using a large number of arrays. If I needed to use about 100 arrays in some formulas but then use a different set of arrays the next time around the loop, what is the easiest way to do it. For example, I have 3 sets of 100 arrays. I may need set 1 or I may need set 2. Whichever one I need, I memcpy set1 into set 4 and set 4 is what I use for the formulas. Set 4 is just kind of temporary storage arrays. I think this is where I'm using so much memory.

Reply With Quote
  #5  
Old December 20th, 2005, 01:25 AM
TechNoFear TechNoFear is offline
Offensive Member
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2002
Location: in the perfect world
Posts: 610 TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 14 m 19 sec
Reputation Power: 25
GDI is Graphical Device Objects. They are fonts, pens, brushes, bmps ect used when drawing to the screen.

9500 is too many GDI and if it is climbing steadily then that is your problem.
8Mb mem is nothing, I have apps that download >100Mb recordsets without issue.

My guess is you are not using SelectObject() properly. SelectObject() pushes the current/default GDI object out. Catch this return and replace it, select it back into the DC. Then delete the created GDI object, release or delete the DC.

Reply With Quote
  #6  
Old December 20th, 2005, 02:03 AM
jjj93421 jjj93421 is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 342 jjj93421 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 2 Days 3 h 34 m
Warnings Level: 10
Number of bans: 1
Reputation Power: 0
Yes, you were right on. I haven't fixed it yet but I'm sure I can now because now I know what it is. Thanks.

Reply With Quote
  #7  
Old December 20th, 2005, 02:24 AM
TechNoFear TechNoFear is offline
Offensive Member
Dev Shed Novice (500 - 999 posts)
 
Join Date: Oct 2002
Location: in the perfect world
Posts: 610 TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level)TechNoFear User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 3 Days 14 m 19 sec
Reputation Power: 25
I'll expect the cheque in the mail then........



(post again if still having issues)

Reply With Quote
  #8  
Old December 20th, 2005, 02:44 AM
jjj93421 jjj93421 is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 342 jjj93421 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 2 Days 3 h 34 m
Warnings Level: 10
Number of bans: 1
Reputation Power: 0
I appreciate the help. I think part of my problem is that I don't fully understand GDI objects. I'm having a hard time finding the leak.

For each :

HDC hdcDesktop= GetDC(NULL);

I have a :

ReleaseDC(NULL, hdcDesktop);

So each one of those checks out that I can see. Where else can a leak occur ? I recently took out a bunch of "Cout" statements. I have two similar programs. One has all of the Cout statements and one doesn't. Each program is nearly identical but one has a memory leak and one doesn't and I'm stumped.

Reply With Quote
  #9  
Old December 20th, 2005, 05:36 AM
jjj93421 jjj93421 is offline
Permanently Banned
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 342 jjj93421 Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 2 Days 3 h 34 m
Warnings Level: 10
Number of bans: 1
Reputation Power: 0
I found it. It was a bad use of Goto / loop . I nearly chopped up the whole program to find it.

Reply With Quote
  #10  
Old December 20th, 2005, 07:23 AM
brifanz brifanz is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Posts: 81 brifanz User rank is Private First Class (20 - 50 Reputation Level)brifanz User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 23 h 35 m 39 sec
Reputation Power: 8
Hi there.

Programmers automate others tasks so others don't mess around with the system...

I think scope ownership is one answer to this kind of problems...

I had the same problem with the GDI object management.
simply because I had to put a ReleaseDC() for every GetDC(),
at first this seems to be very straight-forward but later in projects I started to regret it because I could forget to release the object, or need to have multiple return points in the function and must explicitly call ReleaseDC() before returning from the function or use goto to 'solve' it...

So how about using the language to automate the task?

One mechanism that I found very suitable to avoid such problems, was the use of class scope to dictate the lifetime of object ownership(when you use GetDC() you are in fact gaining ownership of the object at least to some extent)...

The way it work's is quite simple : The class instances are commonly called automatic variables(variables that are allocated in the stack and thus the compiler has the responsibility for their construction/destruction).

Here are some common class utilities that I use quite often in my projects and were very simply to implement(they were written at the same time I was writing this post )

Code:
// An instance of this class gets a given window DC in it's constructor and releases it to in it's destructor.
// Common use :

void DrawSomething(CWnd *pWnd)
{
	LockDC ldc(pWnd);
	ldc()->TextOut("");

	// The compiler will place destructor calls here for each stack based instance...
	// So this means that it will place a call to ~LockDC() here thus creating the desired mechanism!!
}

class LockDC
{
private:
	CWnd *pWnd;
	CDC   *pDC;

public:
	LockDC(CWnd *pWnd) // Class ctor.
	{
		LockDC::pWnd = pWnd; // Copy the window, so we can release the DC later...
		if(pWnd != NULL) pWnd->GetDC(); // if the window is valid get it's DC.
	}

	~LockDC() // Class dtor.
	{
		if(pWnd != NULL) // Was the window passed in the constructor valid?
		{
			if(pDC != NULL) pWnd->ReleaseDC(pDC); // If we got the DC release it...
		}
	}

public:
	inline CDC *operator()() // Inline expansion, use this operator to gain access to the CDC...
	{
		return pDC; // Return the window DC.
	}
};

// This class is very handy in situations you must select a GDI object...
// It will keep the previous selected object of type T into the DC in it's construction and will
// restore the DC state(and if we like it will delete the newObject after using it) in the destructor.

template<class T> class SelectGDIObject
{
private:
	CDC *pDC;	 // The device context.
	T *oldObject; // The object that was previously selected.

	bool deleteAfter; // Do we want to delete the object after using it?

public:
	SelectGDIObject(CDC *pDC, T *newObject, bool deleteAfter = false)
	{
		SelectGDIObject::pDC = pDC;
		SelectGDIObject::deleteAfter = deleteAfter; 
		if(pDC != NULL) oldObject = pDC->SelectObject(newObject);
	}

	~SelectGDIObject()
	{
		if(pDC != NULL) // Was the DC valid?
		{
			T *temp = pDC->SelectObject(oldObject); // Select the old object...
			if((deleteAfter == true) && (temp != NULL)) // Shouls we delete it?
			{
				temp->DeleteObject(); // Delete the object...
			}
		}
	}
};

// Common typedefs 
// To select a font object use SelectFont(pDC, &myFont)!!!

typedef SelectGDIObject<CBrush> SelectBrush;
typedef SelectGDIObject<CPen> SelectPen;
typedef SelectGDIObject<CFont> SelectFont;
typedef SelectGDIObject<CBitmap> SelectBitmap;
typedef SelectGDIObject<CRgn> SelectRegion;

// Don't think that this ends here, I work with databases and this is a good way to work with transactions...



Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Program quits for absolutely no reason


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap