help me to make my program work faster
-
I had written my program, but it work so slow, that all work looks like one big photo album. I tried optimizate with visual studio, but it gave nothig. What could I do to increse program working speed?
Well without knowing anything about your program it is hard to say. But here are some things to look at. What graphics methods are you using? I don't know alot about all of them but I know that setpixel and getpixel are really slow. Do you have unnecisary calculations inside of a loop? In other words if you have a value that will remain the same for the duration of a loop, calculate its value outside the loop so your program doesn't have to repeat the operation thousands or millions of times. Are you rediming large arrays constantly? In particular redim preserve is slow because the computer is actually making a new array and copying the contents over from the old one. I hope this helps, Mike
-
Well without knowing anything about your program it is hard to say. But here are some things to look at. What graphics methods are you using? I don't know alot about all of them but I know that setpixel and getpixel are really slow. Do you have unnecisary calculations inside of a loop? In other words if you have a value that will remain the same for the duration of a loop, calculate its value outside the loop so your program doesn't have to repeat the operation thousands or millions of times. Are you rediming large arrays constantly? In particular redim preserve is slow because the computer is actually making a new array and copying the contents over from the old one. I hope this helps, Mike
-
I use two picturebox's arrays, wich have 10 elenemts, two timers. My form is maximized and transparent. Then the form wasn't trasnparent, program was going on the right speed.
There are any number of reasons as to why your program could run slowly. We don't have enough information to give you an informed opinion. I would guess, though, that you may have memory issues. Take a look in Task Manager and see how much memory your application is using. If it looks as though it's chugging memory like Duff beer, take a look at this article: http://www.marcclifton.com/tabid/79/Default.aspx[^]
Deja View - the feeling that you've seen this post before.
-
I use two picturebox's arrays, wich have 10 elenemts, two timers. My form is maximized and transparent. Then the form wasn't trasnparent, program was going on the right speed.
Best thing to do would be to post the sub/function that you think is acting slowly (not the whole program) with a little explaination of what you are trying to do with it. Even if I don't have the answer someone else may. Otherwise we can only guess what the problem is. If you are not sure which sub/function is the problem then try setting some breakpoints and run through your program and see where it is getting hung up.
-
Best thing to do would be to post the sub/function that you think is acting slowly (not the whole program) with a little explaination of what you are trying to do with it. Even if I don't have the answer someone else may. Otherwise we can only guess what the problem is. If you are not sure which sub/function is the problem then try setting some breakpoints and run through your program and see where it is getting hung up.
private: System::Void tmr_for_move_Tick(System::Object^ sender, System::EventArgs^ e) { Move_usr(); if(b_usr.pct->Visible == true) Move_bl_usr(); for(int i=0; ipct->Visible == true) Move_bl_em(i); if(b_usr.pct->Visible == true) Check_hit_em(i); if(b_em[i]->pct->Visible == true) Check_hit_usr(i); else if(em[i]->pct->Visible == true) Shooting_em(i); } } private: void Move_em(int i){ if(em[i]->pct->Left + em[i]->step_x > min_x && em[i]->pct->Left + em[i]->step_x < max_x) em[i]->pct->Left += em[i]->step_x; else em[i]->step_x *= -1; if(em[i]->pct->Top + em[i]->step_y > min_y && em[i]->pct->Top + em[i]->step_y <= max_y) em[i]->pct->Top += em[i]->step_y; else em[i]->step_y *= -1; if(em[i]->pct->Left == max_x) em[i]->step_x = - em[i]->step_x; if(em[i]->pct->Top == max_y - 58) em[i]->step_y = - em[i]->step_y; if(em[i]->step_x > 0) em[i]->pct->Load("e_r.jpg"); else if(em[i]->step_x < 0) em[i]->pct->Load("e_l.jpg"); if(em[i]->step_y > 0) em[i]->pct->Load("e_d.jpg"); else if(em[i]->step_y < 0) em[i]->pct->Load("e_u.jpg"); } Other procedures are same, but move different object. private: object usr, b_usr; private: static unsigned short int hits = 0; private: static unsigned short int n = 10; private: static unsigned short int m = 32; private: static array^ em; private: static array^ b_em; ref struct object { int step_x, step_y; System::Windows::Forms::PictureBox^ pct; };
-
I use two picturebox's arrays, wich have 10 elenemts, two timers. My form is maximized and transparent. Then the form wasn't trasnparent, program was going on the right speed.
Hi, So the form's transparancy is the key factor. Does it have to be transparant ? And are you using double-buffering ? If not, I would recommend you try it. :)
Luc Pattyn [My Articles]
-
Hi, So the form's transparancy is the key factor. Does it have to be transparant ? And are you using double-buffering ? If not, I would recommend you try it. :)
Luc Pattyn [My Articles]