Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Muhammad

Pages: [1]
1
C - C++ / Re: C++ Help!
« on: May 03, 2013, 05:41:22 am »
I'm not sure why this is happening .. If you enter 2 at the end of the program it will break you out of the while loop.

Try adding this  at line 409:

Code: (cpp) [Select]
if (decision == 2 ) break;

2
C - C++ / Re: C++ Help!
« on: May 03, 2013, 05:02:43 am »


yep, you do that outside the while loop. your code right now is like:


Code: [Select]
case = true;     // initial value
while(case)
{


}                     // end of while loop (case still equals the initial value)
case = false; // you'll never get here !




you should change the decision at the end of the while loop

3
C - C++ / Re: C++ Help!
« on: May 03, 2013, 04:51:00 am »
so at the very beginning you set
Code: [Select]
decision == 1


but you never change its value, hence never break from the while loop :)

4
C - C++ / Re: speed/optimization in c++
« on: May 03, 2013, 04:32:21 am »
@Xires
well, I know about bitwise operator, but I don't use them very often (maybe I should try them whenever possible), and I will make a piece of code just to get a feeling of the speed of pre-increment tip.

Now I'll take a look at what I've got from the replys. Thanks all :)

5
C - C++ / Re: C++ Help!
« on: May 03, 2013, 04:29:15 am »
can you explain the problem, so I can help ?

6
Found it on the Webs / Re: The most talented troll on internet :D
« on: May 02, 2013, 02:39:49 pm »
loooooooooool I've spent lastnight reading the posts there. A very awesome website  ;D .
Thanks for the share !

7
C - C++ / Re: speed/optimization in c++
« on: May 02, 2013, 02:21:32 pm »
@rasenove
oh sorry I should have introduced my self there, anyways, I'll do it again there =D

Thanks for the link you provided, but actually I didn't mention that I searched for optimization many times before, and I did came across this website and I've recently downloaded a book called "Optimizing software in C++" by Agner Fogb that helped me.

To make my question clear: for example there is a tip saying (I've seen this one during my search):
instead of doing this: x/2.0 do x*0.5 (multiplication is faster) ..

Classes are very nice to organize your code but it slows down you code.
I need this kind of tips. increasing the speed of my code with a fraction of a second will be something :)

I've learned c++ from cplusplus.com, youtube, and most of the time I just googled what I needed to know, I've got most of the answers/ideas from stackoverflow.

I'm really looking for tips that may look very basic (even silly) to any of you to say, but actually I don't have these tips.

@Factionwars


here is a snippet of a code I did some optimization for:


the loop is to update an array (line segments) with new segments after trimming the line.
From timing results I've found that making the three variables c1,c2,c3 increased the speed a bit since I only now caculate each one one time
 
Code: [Select]

        bool c1,c2,c3;


for(iseg = 0 ; iseg < num ; iseg++)
{
min = _tmp_line[iter];iter++;

max = _tmp_line[iter];iter++;

if(!( pmin < min && pmax > max ))
{
c1 = pmin > min && pmin < max && pmax > max;


if(c1)
{
_line[iter2] = min;iter2++; //1st seg
_line[iter2] = pmin;iter2++;
}
c2 =  pmax < max && pmax > min && pmin < min;

if(c2)
{
_line[iter2] = pmax;iter2++; //1st seg
_line[iter2] = max;iter2++;
}
c3 = pmin > min && pmax < max; 
if( c3 && !c1 && !c2 ) //split
{
_line[iter2] = min;iter2++; //1st seg
_line[iter2] = pmin;iter2++;

_line[iter2] = pmax;iter2++; //2nd seg
_line[iter2] = max;iter2++;


}


if(!c1 && !c2 && !c3)
{
_line[iter2] = min;iter2++; //1st seg
_line[iter2] = max;iter2++; //1st seg
}
}


thanks for you replys guys !

8
C - C++ / speed/optimization in c++
« on: May 02, 2013, 12:40:36 am »
Hi guys,

I've been writing c++ for more than two years, and It's easy for me right now to write any code, yet the speed of my codes is slow (comparing to what it should be). I've not studied programming/algorithms (my study area is very far from this field) maybe that's the reason why I'm not familiar with basic stuff to get a code that is fast enough.

So, I'd like you to advice me on how to learn this basic speed tips like what to do and what to avoid (books, websites or any are welcomed).     

one last thing :)
I've recently joined EZ, actually just yesterday and by chance too  :D , and I've really enjoyed what you've got here. I looked at the different sections on the forum and definitely I'll be spending some time here from now on :)

cheers

Pages: [1]