While loop - extremely slow?
#3

The 2 functions i use:
PHP Code:
new Indexes[MAX_MESSAGES];
stock FreeIndexes()
{
    for(new 
=0iMAX_MESSAGESi++)
    {
        
Indexes[i] = 0;
    }
}
stock getIndex()
{
    new 
Index random(MAX_MESSAGES-1), j;
    for(new 
=0iMAX_MESSAGESi++)
    {
        if(
Indexes[i] != Index)
        {
            if(
Indexes[i] == 0)
            {
                
Indexes[i] = Index;
                break;
            }
             
Index;
        }
    }
    return 
j;

FreeIndses() is called on starting of the command.


I cant use the normal for loop for the only reason that i want to access random elements within the array, not crescent or decreasing, thus i made the function getIndex which checks if the index hasnt been used already, if not return it & store it into the indexes array... until its full...

I couldnt think of another way... i know i am using alot of loops... but is there any other way?
Response is kinda 4-5 seconds.
Reply


Messages In This Thread
While loop - extremely slow? - by iLearner - 08.02.2017, 18:58
Re: While loop - extremely slow? - by NaS - 08.02.2017, 19:09
Re: While loop - extremely slow? - by iLearner - 08.02.2017, 19:36
Re: While loop - extremely slow? - by NaS - 08.02.2017, 21:35
Re: While loop - extremely slow? - by iLearner - 08.02.2017, 22:00
Re: While loop - extremely slow? - by NaS - 08.02.2017, 23:25
Re: While loop - extremely slow? - by Lordzy - 09.02.2017, 01:02
Re: While loop - extremely slow? - by iLearner - 09.02.2017, 17:24
Re: While loop - extremely slow? - by NaS - 09.02.2017, 19:16
Re: While loop - extremely slow? - by iLearner - 09.02.2017, 22:02

Forum Jump:


Users browsing this thread: 1 Guest(s)