Results 1 to 10 of 10

Thread: Reduce Memory usage/leak in a script/TPAS - need help and revision

  1. #1
    Join Date
    Sep 2008
    Posts
    754
    Mentioned
    8 Post(s)
    Quoted
    275 Post(s)

    Default Reduce Memory usage/leak in a script/TPAS - need help and revision

    Right, so I've written a script in pascal to be used in Simba, now what i need - is a direction - a direction to pass on to the next level.
    Surprisingly the script works well, better than expected - but that comes at a cost, over-usage of memory.

    What i need to do: am i doing it right, or doing it wrong: how to Free TpointArray and TpointArrays.

    First:This is how i free The bitmaps, i free them when ever they are called, i get no errors what-so-ever in my script regarding bitmaps and i've debugged them and they all freed properly, is this form correct?
    Code:
    Function OutOfprayer: Boolean;
    begin
    Zero := BitmapFromString(5, 9, 'meJwzdfA0dfCUn/EfiExhbFM7DwYG' +
    'BqggjG1s4wokgWw4AysXohKZi1ULRASuEgBRMCjb');
    SetBitmapName(Zero, 'Zero Bitmap' );
    if (FindBitmapToleranceIn(Zero,X,y,MIX1, MIY1, MIX2, MIY2, 10)) then
    begin
      FreeBitmap(zero);
    Isoutofprayer := true;
    result := true;
    end
    else
    begin
      FreeBitmap(zero);
    
    Isoutofprayer := false;
    Result := false;
    end;
    end;
    Now what i am doing wrong is that am using the FindColorsTolerance(function) a lot in my script and i never defined the length, or amount of my tpoints, what i need is to free them from memory after they are used (is that even possible?)

    For example:

    Code:
    Function Rangepray: Boolean;
    begin
    tmpCTS := GetColorToleranceSpeed;
    ColorToleranceSpeed(2);
    SetColorSpeed2Modifiers(0.18, 0.10);
    if (FindColorsTolerance(Monster, 4470582, MSX1, MSY1, MSX2, MSY2, 7)) then
    begin
    ColorToleranceSpeed(tmpCTS);
    SetColorSpeed2Modifiers(0.2, 0.2);
    range := true;
    result := true;
    end
    else
    begin
    ColorToleranceSpeed(tmpCTS);
    SetColorSpeed2Modifiers(0.2, 0.2);
    range := false;
    result := false;
    end;
    ColorToleranceSpeed(tmpCTS);
    SetColorSpeed2Modifiers(0.2, 0.2);
    end;
    My question is in: (FindColorsTolerance(Monster, 4470582, MSX1, MSY1, MSX2, MSY2, 7))
    my TPA is monster but i never once defined what monster is, What command do i need to add - that wont change anything/hinder my script but will free my Tpa after its used? setlength?.

    I did follow TPA guides and what not, but i could never get them to do what i want them to do, the way i use it call it but never define it just makes the script perform better - but at cpu and ram cost, so how do i free it?? if any one knows please reply.
    Last edited by samerdl; 04-18-2013 at 02:03 PM.

  2. #2
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    Simba should free all data when its not being used.. if you really want to make sure you can put setLength(monster, 0) when you've finished with it.

  3. #3
    Join Date
    Mar 2007
    Posts
    393
    Mentioned
    1 Post(s)
    Quoted
    98 Post(s)

    Default

    I have very slow PC. So TPAs sometime freeze my screen. This happens when script doesn't find TPA right away. I try this setLength out too...
    any other suggestions?

  4. #4
    Join Date
    Sep 2008
    Posts
    754
    Mentioned
    8 Post(s)
    Quoted
    275 Post(s)

    Default

    Quote Originally Posted by t4q View Post
    I have very slow PC. So TPAs sometime freeze my screen. This happens when script doesn't find TPA right away. I try this setLength out too...
    any other suggestions?

    Yep still continuing, anything else we can do?

  5. #5
    Join Date
    Nov 2011
    Location
    England
    Posts
    3,072
    Mentioned
    296 Post(s)
    Quoted
    1094 Post(s)

    Default

    How much ram do you have..

  6. #6
    Join Date
    Mar 2007
    Posts
    393
    Mentioned
    1 Post(s)
    Quoted
    98 Post(s)

    Default

    1 GB, lol

  7. #7
    Join Date
    Jan 2009
    Location
    Turlock/LA, California
    Posts
    1,494
    Mentioned
    3 Post(s)
    Quoted
    66 Post(s)

    Default

    Simba Code:
    Function Rangepray: Boolean;
    var
      tmpCTS: integer;
      Monster: tpointarray;
    begin
      tmpCTS := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(0.18, 0.10);

      result := FindColorsTolerance(Monster, 4470582, MSX1, MSY1, MSX2, MSY2, 7);
      range:= result;

      ColorToleranceSpeed(tmpCTS);
      SetColorSpeed2Modifiers(0.2, 0.2);
    end;

    does that altered version of ur code work better?
    Last edited by x[Warrior]x3500; 04-18-2013 at 10:02 PM.

  8. #8
    Join Date
    Sep 2008
    Posts
    754
    Mentioned
    8 Post(s)
    Quoted
    275 Post(s)

    Default

    Quote Originally Posted by x[Warrior]x3500 View Post
    Simba Code:
    Function Rangepray: Boolean;
    var
      range: boolean;
      tmpCTS: integer;
      Monster: tpointarray;
    begin
      tmpCTS := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(0.18, 0.10);

      result := FindColorsTolerance(Monster, 4470582, MSX1, MSY1, MSX2, MSY2, 7);
      range:= result;

      ColorToleranceSpeed(tmpCTS);
      SetColorSpeed2Modifiers(0.2, 0.2);
    end;

    does that altered version of ur code work better?
    Question, is it okay to Declare TPA's in global var and use the same TPA for al FindColorsTolerance, or does it have to be different? (i use the same TPA for all the commands and it works just fine, i also tried to call it locally but that made no difference), just double checking.

    -- Both versions work, I use that formula for colors that don't need CTS, but am trying it right now, what made the change for me was Setting the TPA'S length and yes, from now on i will shorten my functions, much easier. (it works the same!)



    THANKS!

  9. #9
    Join Date
    Jan 2009
    Location
    Turlock/LA, California
    Posts
    1,494
    Mentioned
    3 Post(s)
    Quoted
    66 Post(s)

    Default

    Quote Originally Posted by samerdl View Post
    Question, is it okay to Declare TPA's in global var and use the same TPA for al FindColorsTolerance, or does it have to be different? (i use the same TPA for all the commands and it works just fine, i also tried to call it locally but that made no difference), just double checking.

    -- Both versions work, I use that formula for colors that don't need CTS, but am trying it right now, what made the change for me was Setting the TPA'S length and yes, from now on i will shorten my functions, much easier. (it works the same!)

    THANKS!
    yah all i did was take out the redundant part of your code and shorten it to 2 lines. then i change the globals to locals. i thought that might work, as it would be forced to relinquish the memory of the tpa once the function is done.

  10. #10
    Join Date
    Sep 2008
    Posts
    754
    Mentioned
    8 Post(s)
    Quoted
    275 Post(s)

    Default

    Quote Originally Posted by x[Warrior]x3500 View Post
    yah all i did was take out the redundant part of your code and shorten it to 2 lines. then i change the globals to locals. i thought that might work, as it would be forced to relinquish the memory of the tpa once the function is done.
    ha yeah.. i was doing double work, i'll make local vars then for each TPA and not use global.

    Thanks again, script works a lot smoother now.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •