SRL Archive - OSR Help

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


samerdl

2013-04-18 09:38:26

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?

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:


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.

Olly

2013-04-18 09:54:29

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.

t4q

2013-04-18 14:12:40

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?

samerdl

2013-04-18 16:06:50

From: t4q
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?

Olly

2013-04-18 16:20:22

How much ram do you have..

t4q

2013-04-18 16:57:37

1 GB, lol :D

x[Warrior]x3500

2013-04-18 17:06:28


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?

samerdl

2013-04-18 19:02:25

From: x[Warrior]x3500

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!

x[Warrior]x3500

2013-04-18 20:33:10

From: samerdl
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.

samerdl

2013-04-19 05:54:46

From: x[Warrior]x3500
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.