Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 00:22

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Mind = Blown. Quick Question

Discussion on Mind = Blown. Quick Question within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
12k's Avatar
 
elite*gold: 0
Join Date: Jul 2011
Posts: 218
Received Thanks: 33
Mind = Blown. Quick Question

The difference between the 2 sections of code is causing a 50% CPU usage difference, im just wondering how, and why o.o.

0% CPU Usage:
Code:
            uint CurrentTime = Network.Imports.timeGetTime();
            while (Running)
            {
                CurrentTime = Network.Imports.timeGetTime();
                if (Players.Count > 0)
                {
                    Mobs.Monster[] _mobz = Monsters.Values;
                    foreach (Mobs.Monster Mob in _mobz)
                        Mob.Step(_mobz, CurrentTime);
                    Thread.Sleep(Settings.MobRestTime); //1500
                }
                else
                    Thread.Sleep(5000);
            }
50% CPU Usage:
Code:
            while (Running)
            {
                uint CurrentTime = Network.Imports.timeGetTime();
                if (Players.Count > 0)
                {
                    Mobs.Monster[] _mobz = Monsters.Values;
                    foreach (Mobs.Monster Mob in _mobz)
                        Mob.Step(_mobz, CurrentTime);
                    Thread.Sleep(Settings.MobRestTime); //1500
                }
                else
                    Thread.Sleep(5000);
            }
Literally the only difference is whether or not im constructing the variable inside or outside the loop. Would really love some insight on this.
12k is offline  
Old 01/27/2013, 14:04   #2


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
Theres actually little to no difference between the two examples as far as the compiler is concerned, that 50% spike should not be caused by the way you declare CurrentTime.
Korvacs is offline  
Thanks
1 User
Old 01/27/2013, 19:06   #3
 
Mr.Human's Avatar
 
elite*gold: 10
Join Date: May 2008
Posts: 292
Received Thanks: 199
honestly in my opinion it would be that top loop sets the current time once then the bottem loop sets the time every time the loop resets resulting into importing the time multiple times which is causes the extra cpu usage but im fairly new to c++ so i would probably trust Korvacs opinion more
Mr.Human is offline  
Old 01/27/2013, 21:38   #4
 
Lateralus's Avatar
 
elite*gold: 0
Join Date: May 2005
Posts: 1,892
Received Thanks: 918
Yeah, Korvacs is right. Also, I'd use Environment.TickCount rather than importing timeGetTime, as they do the exact same thing (at least all that you'll need throughout your source).
Lateralus is offline  
Old 01/27/2013, 22:39   #5


 
Korvacs's Avatar
 
elite*gold: 20
Join Date: Mar 2006
Posts: 6,125
Received Thanks: 2,518
Quote:
Originally Posted by *scott^kurack* View Post
honestly in my opinion it would be that top loop sets the current time once then the bottem loop sets the time every time the loop resets resulting into importing the time multiple times which is causes the extra cpu usage but im fairly new to c++ so i would probably trust Korvacs opinion more
No, they both set the CurrentTime variable within the loop, the top one just allocates it beforehand.
Korvacs is offline  
Old 01/28/2013, 00:18   #6
 
12k's Avatar
 
elite*gold: 0
Join Date: Jul 2011
Posts: 218
Received Thanks: 33
Quote:
Originally Posted by Korvacs View Post
Theres actually little to no difference between the two examples as far as the compiler is concerned, that 50% spike should not be caused by the way you declare CurrentTime.
yeah, this was my thought exactly, thats why my mind is like blown haha. It literally changes the CPU usage by 50%. No idea why.

@Lateralus Thanks for the advice. It seems as if i was told that timegettime never went negative whereas tickcount did. So was better to use for general purpose. Now that ive done more reading, makes more sense to go with tickcount.
12k is offline  
Old 01/28/2013, 11:58   #7
 
Mr_PoP's Avatar
 
elite*gold: 0
Join Date: Apr 2008
Posts: 759
Received Thanks: 285
try to not use P/Invokes as possible as you can!

because :-

1-Marshalling between managed/unmanaged types has an additional overhead
2-Doesn't work in medium trust
3-Not quite intuitive and could lead to subtle bugs like leaking handles, corrupting memory, ...
4-It could take some time before getting it right when looking at an exported C function
5-Problems when migrating from x86 to x64
6-When something goes wrong you can't simply step into the unmanaged code to debug and understand why you are getting exceptions. You can't even open it in Reflector :-)
7-Restricts cross platform interoperability (ie: you can't run under Linux if you rely on a Windows-only library).

Conclusion: use only if there's no managed alternative or in performance critical applications where only unmanaged libraries exist to provide the required speed.
Mr_PoP is offline  
Reply


Similar Threads Similar Threads
quick question
04/01/2010 - Dekaron - 0 Replies
ok just finally today updated this a6 and everytime i run the game it says dekaron exe has stopped working im usin windows vista ..any1 kno wats up if ya do id apreciate the help =P
quick question
12/13/2009 - CO2 Programming - 5 Replies
I broke my wrist last week,so I got A few weeks of to play with getting myown proxy working.Ive been using A private one but it is lacking A few features and I dont got the source...so quick question just to conferm.. the first packet sent(log-in) uses the old enc right? Then the first packet recived starts the BF.DH shit right with the use of the init key?
Very quick question need quick answer!
10/26/2009 - Dekaron - 5 Replies
On line 21 of the CE non agro, what is the regular speed of the mobs? what do I change?? I wanna non agro that doesnt make the monsters so speedy... thansk!
Just a quick question.
06/06/2009 - Conquer Online 2 - 4 Replies
Ive been on these forums for a few days now and was wondering is there any Auto nado or zoom hacks? I cant seem to find any working ones, the zoom hack will be more important to me atm. If there is a working zoom thats safe anywhere could someone please post the link on this thread, would be great if you could and much appreciated. Thanks :)
Quick Question
11/12/2006 - Conquer Online 2 - 5 Replies
Is there a macro that attacks 4 stakes in tg? With FB/SS X=Stake o=Char X X o X X



All times are GMT +2. The time now is 00:22.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.