SRL Archive - News and General

i think writeln() leaks memory


Feroc1ty

2011-02-28 14:29:35

my script has debug that writes a lot of lines, and i noticed when its off simba doesn't use NEARLY as much memory as it does with debug enabled



anyone else notice this?

mastaraymond

2011-02-28 14:34:23

That's because it allocates memory for the string you wrote.. Try calling "ClearDebug;" once in a while ;-).

anonymity

2011-02-28 15:27:22

What if you need those debugs later? And it stacks a few in there every so often?

Ex: sometimes I set a script to go on a computer and I don't come back to it until a few days later…. there are a lot of lines of debug to go through.

ReadySteadyGo

2011-02-28 15:36:37

Save them to a .txt file?

Floor66

2011-02-28 15:37:21

There doesn't seem to be a "GetDebugText" in Simba. Is there an equivalent?

anonymity

2011-02-28 15:42:20

Yes.. it is possible.

You have to make a txt file and send all of your messages there… unfortunately, this always seems fail for me, so no I haven't been able to get it to work.

Floor66

2011-02-28 15:48:04

Well then what's the equivalent for GetDebugText in Simba :P I've been trying to find it >.<

MylesMadness

2011-02-28 15:51:12

From: Floor66
Well then what's the equivalent for GetDebugText in Simba :P I've been trying to find it >.<
You can just replace all the writeln with Debug(). And then have debug have a writeln function and a save line function.

anonymity

2011-02-28 17:08:57

OR, you can do this. This is how I save my 'writeln's out of simba. It seems to work nicely.

Program FileLogging;

Var
filePath: string;
newFile: integer;

Function DateOfYear: string;
var
y, m, d : Word;
months: TStringArray;
begin
months := ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'June', 'July', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
DecodeDate(date, y, m, d);
Result := (inttostr(y) + '.' + inttostr(m) + '.' + inttostr(d));
end;

Function ScriptRunTime: string;
var
S, M, H, D : integer;
begin
if GetTimeRunning < (24*60*60*1000) then
begin
ConvertTime(GetTimeRunning, H, M, S);
Result := ('ran for ' + IntToStr(H) + ' hrs, ' + IntToStr(M) + ' min, ' + IntToStr(S) + ' sec');
end else
begin
ConvertTime(GetTimeRunning, H, M, S);
D := Floor(H/24);
H := H mod 24;//remainder
Result := ('ran for ' + IntToStr(D) + ' days, ' + IntToStr(H) + ' hours, ' + IntToStr(M) + ' minutes, ' + IntToStr(S) + ' seconds');
end;
end;

Function TimeOfDay: string;
var
H, M, S, Ms: Word;
begin
DecodeTime(Now, H, M, S, Ms);
Result := (Padz(IntToStr(H), 2) + '.' + Padz(IntToStr(M), 2) + '.' + Padz(IntToStr(S), 2));
end;

Procedure TesterLog(action: string);
begin
WriteFileString(newFile, '... ... ... ...' + #13#10); //* In Windows #13#10 makes new line
WriteFileString(newFile, 'Net Tester ' + action + ':' + #13#10);
WriteFileString(newFile, DateOfYear + #13#10);
WriteFileString(newFile, TimeOfDay + #13#10);
if (action = 'ended') then
WriteFileString(newFile, ScriptRunTime + #13#10);
WriteFileString(newFile, '... ... ... ...' + #13#10);
end;

{**************************************************************\
* You must create the folder directory before this will work *
\**************************************************************}
Procedure StartLogging;
begin
filePath := 'C:\Simba\Logs\Tests\'; //* need to create the 'Logs' & 'Tests' before this works
newFile := CreateFile(filePath + DateOfYear + '_' + TimeOfDay + '.txt');
end;

Procedure DoStuff;
begin
Wait(1000 + random(1000));
WriteFileString(newFile, 'doing some stuff' + #13#10);
wait(1000 + random(1000));
end;


Begin
ClearDebug;
StartLogging;
TesterLog('started');
DoStuff;
TesterLog('ended');
CloseFile(newFile);
End.

Or you can do it however you want. This is the short version:
Program FileLoggingShimple;

Var
filePath: string;
newFile: integer;

Begin
filePath := 'C:\Simba\Logs\Tests\'; //* must create the 'Logs' & 'Tests' folders before this works
newFile := CreateFile(filePath + 'anyfilename' + '.txt');
WriteFileString(newFile, 'doing some stuff' + #13#10); //* In Windows #13#10 makes new line
CloseFile(newFile);
End.

Feroc1ty

2011-02-28 18:01:03

Hmmm, I'll save it to a text file and cleardebug every half an hour or an hour, see which one is better, but I personally think creating a form with custom debug would allow you to allocate the same amount of memory but know its locations and values, allowing you to manipulate them much more easily.

anonymity

2011-02-28 18:11:15

Yea, I was going to do that, but if simba crashes or I loose power, then I have no log at all.
Same with the writing to file instead of writing to debug; if you loose power, you don't get the log. However, from my tests, if simba crashes it will have saved everything it already posted into the file. - The file way also doesn't hold a constant stacking stream of memory to the system through simba. I don't know all about the +/-'s of using WriteFileString() instead of writeln.

Bad Boy JH

2011-02-28 18:32:55

Just an idea, what if we could clear part of the debug…

Feroc1ty

2011-02-28 19:05:07

There should be like an option in SIMBA executable to limit the amount of Debug messages allocated to memory, and maybe even have an option to limit the memory value rather than the amount.

Bad Boy JH

2011-02-28 19:11:56

The second would probably be better, first would proabably easier to implement