PenUltima Online

It is currently Tue Oct 07, 2008 8:42 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Another trouble with allocation
PostPosted: Fri Dec 07, 2007 12:00 pm 
Offline

Joined: Tue Mar 20, 2007 7:17 am
Posts: 101
Location: Poland
I wrote a simple script that scanns whole world for mobiles and restarts them.

And when the script was in about half of the way an allocation problem occured (POL097 was restarted minute earlier)

code:

Code:
program resmobs(kto)
var list_realms_sp := {"britannia","ilshenar"};
        foreach map in (list_realms_sp)
            var i := 0;
            for(i := -100; i <= 120; i:=i+20)               
                var x := 0;
                var y := 0;               
                for(x:=50;x<=pobierz_wymiary(map)[1];x:=x+100)
                    for(y:=50;y<=pobierz_wymiary(map)[2];y:=y+100)
                        print("kolejna wspolrzedna: "+x+"/"+y+"/"+i+" mapa: "+cstr(map));
                       
                        res(x,y,i,map);
                       
                       
                        sleepms(20);
                    endfor //y
                endfor  //x                             
            endfor   //z
        endforeach 
    sendsysmessage(kto,"Zakonczono restartowanie mobow");
endprogram

function res(ax,ay,az,amap)
   
    foreach wpis in (ListMobilesNearLocation( ax,ay,az, 55, cstr(amap) ))
        sleepms(2);
        if(wpis.npctemplate)
            print("Restart moba: "+wpis.name);
            RestartScript(wpis);
        endif
        sleepms(10);
    endforeach
   
endfunction



I`m really troubled with this allocation problem so I search everywhere


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 12, 2008 4:59 am 
Offline

Joined: Sat Feb 04, 2006 6:26 pm
Posts: 558
The WoD scripts do a similar thing although it was written for just britannia and so the realms stuff is different. Are you checking that it's not trying to search outside realm.width etc?
I have no idea what pobierz_wymiary(map)[1]; is in your script.


Code:
program textcmd_restartai(character, ai_script)
   if ( !ai_script )
      SendSysMessage(character, "You must provide an NPC script to restart.");
      return 0;
   endif

   var number := 0;
   var x, y;

   for ( x := 6144 ; x > 64 ; x -= 128 )
      SendSysMessage(character, "Restarting NPCs, X=" + x);
      for ( y := 64; y < 4096; y += 128 )
         foreach item in ListObjectsInBox(x - 64, y - 64, -128, x + 64, y + 64, +127, character.realm)
            if ( item.npctemplate )
               if ( item.script[ai_script] )
                  RestartScript(item);
                  number := number + 1;
               endif
            endif
         endforeach
      endfor
      sleep(1);
   endfor
   SendSysMessage(character, "Total NPCs restarted: " + number);
endprogram


I use this script occasionally and have never had memory allocation problems with it. Of course I am not straying to Ilshenar with this script!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 12, 2008 6:24 am 
Offline

Joined: Tue Mar 20, 2007 7:17 am
Posts: 101
Location: Poland
pobierz_wymiary function is just simple function to recive max coordinates of map


case(realm)
"britannia": return {britx,brity};
"ilshenar": return {ilshx,ilshy};
endcase

I made some tests... And I think there is an error in elsewhere

start.src <- here

a simple loop in start.src and my server has allocation error after 10s


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 12, 2008 9:34 am 
Offline
User avatar

Joined: Fri Feb 10, 2006 8:08 am
Posts: 327
Location: Myrtle Beach, South Carolina
Seems like you have a lot of unnecessary code. Just try using ListObjectsInBox with the top left corner of the map(0,0,-127(min z height)) and whatever the realm bottom x y is with a z of 126(max z height). Here's an example I use to restart all npcs.

Code:
use os;
use uo;

include "include/client";

program TextCMD_Test(mobile)

   var objects := ListObjectsInBox(0, 0, -127, 6144, 4096, 126, mobile.realm);
   var count := 0;

   foreach object in (objects)
      if ( object.IsA(POLCLASS_NPC) )
         RestartScript(object);
         count := count + 1;
      endif
      SleepMS(2);
   endforeach

   SendSysMessage(mobile, "Restarted "+count+" npcs.", FONT_NORMAL, 2479);

endprogram


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 12, 2008 6:32 pm 
Offline

Joined: Sat Feb 04, 2006 6:26 pm
Posts: 558
I was always scared of creating an array that big :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 13, 2008 1:11 am 
Offline

Joined: Sat Feb 04, 2006 5:49 pm
Posts: 772
Location: Chicago, IL USA
Its not too bad to use an array that big as long as you're obviously not iterating through it excessively in a short period of time.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 13, 2008 12:47 pm 
Offline

Joined: Tue Mar 20, 2007 7:17 am
Posts: 101
Location: Poland
Hem, and what about a memory usage? My script should keep a constant memory usage. What if a script caches an array 20000 size big ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 13, 2008 6:18 pm 
Offline
POL Developer
User avatar

Joined: Wed Jan 25, 2006 2:30 am
Posts: 419
Location: San Diego, California
Well if its an array of stuff that falls under UObject like mobiles and items then it uses very little memory. In the back end it would just be pointers to the actual object rather than a copy.

If you have an array of strings, and numbers, then you take up more memory because every instance is another object in memory until it goes out of scope and is deleted.

_________________
-Austin


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Style based on FI Subice by phpBBservice.nl