• Welcome to Vice City Multiplayer.
 
Menu

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.

Show posts Menu

Messages - Ginarrbrik

#1
Support / Re: two questions
September 08, 2010, 03:31:06 PM
Thankyou Skirmant,

I assume this means that coding my script in pawn is out of the question as i cannot complete it with defective pawn functions,

one a side note, I noticed in your other post you mentioned squirrel

1) how do i add squirrel into vcmp?
2) does it support a greater/thorough list of functions that matches those of mirc, allowing me to rewrite my script.

Regards, GKr
#2
Support / two questions
September 08, 2010, 11:17:51 AM
Hello,

I have noticed that i cannot rewrite my mirc code to pawn because not all the pawn functions are working, and quite a lot are not available to me.

I have two questions,

when will this be rectified? and when is the next release date for vcmp?

Regards, GKr
#3
Lesson Three:

Efficient HashTable Searching with loops:

Sometimes it's better to use a regular loop and a regular If (V1 iswm V2) sentence,
rather than looping through certain $identifiers that have Wildmatch options in them.


The best way to explain this is by an example using $hget to find certain items in a hash table.

For example, look at both these loops:

Loop One:

var %a = 1

while ($hfind(HashTable,*wildcard*,%a,w)) { 

  ;Do stuff here

  inc %a

}


Loop Two:

var %a = 1

while ($hget(HashTable,%a).item) {

  var %item = $v1

  if (*wildcard* iswm %item) {

    ;Do stuff here

  }

  inc %a

}


Although the first loop looks much neater and exploits the $hfind identifier to find you all the matching items, it will still take about twice as much time to resolve.

That happens because the $hfind identifier tries each time to find the next matching item, but it starts each time from the beginning of the Hash table. So if you have a lot of items that match the wildcard it will go over the the entire Hash table over and over.

But the second loop will just go over the Hash table once, and find all the matches.
#4
Lesson Two:

Identifiers and Loops:

Try not to use $identifiers in a while loop's argument.

If you know that the $identifier will return a constant value that won't be changed in the loop's process, then it's better to set the $identifiers value to a %variable, and then use the %variable as the argument.

That's because the loop will evaluate the $identifier on each run to check if the value hasn't changed.

Just to show you how much CPU you can change:

alias test {

  var %ticks = $ticks

  var %a = 1

  while (%a < $lines(test.ini)) {

    inc %a

  }

  echo -a $calc($ticks - %ticks)

}

This little alias will take 1297 ticks (test.ini has 976 lines)


But if I'd put the $lines value in a %variable, and use the %variable in the argument:

alias test {

  var %ticks = $ticks

  var %a = 1

  var %lines = $lines(test.ini)

  while (%a < %lines) {

    inc %a

  }

  echo -a $calc($ticks - %ticks)

}

This takes only 16 ticks to process.
And that's because it doesn't have to process the $lines identifier 976 times.
#5
Script Showroom / Saving CPU/ Memory usage with loops
August 29, 2008, 02:07:50 PM
Saving CPU/ Memory usage with loops.


  alias iniloop {
    var %a = 0,%b = 0,%c
    while (%a < $ini(test.ini,MYSECTION,0)) {
      %b = $readini(test.ini,MYSECTION,$ini(test.ini,MYSECTION,%a))
      %c = $ini(test.ini,MYSECTION,%a)
      inc %a
      if (%b == MyItem2) echo -a Item: %b - Value: %c
    }
  }


The initialization file: (Called Test.ini)

[MYSECTION]
MyItem1=MyValue1
MyItem2=MyValue2
MyItem3=MyValue3
MyItem4=MyValue4
MyItem5=MyValue5




How to Test your loops:

The best way to check yourself, is to make a loop that will repeat itself about 10000 times,
and in it try all sorts of ways to do what you want, and then see how many ticks it takes for the loop to finish.


alias test {
   var %ticks = $ticks
   var %a = 1
   while (%a < 10000) {

       ;The method you're checking comes here

   }
   echo ?a $calc($ticks - %ticks)
}


Just remember that 1000 ticks are equal to about 1 second.


Note:
Allot of coders are under the impression that the more lines a script holds, the more inefficient it is.

They are presuming incorrect.

The Memory eating and cpu eating elements inside a script are usually down to poorly designed loops.


Try it for yourself.