Sign in to follow this  
Followers 0
toofat

Script & Memory Usage

7 posts in this topic

#1 ·  Posted (edited)

I would be grateful if someone could explain to me why function "_Test2()" doesn't consume much memory while function "_Test1()" uses more and more memory. Functions should do the same thing. This happens in the case when a prerequisite is met so please do that.

Please run the script with "_Test1()" and "_Test2()" function and then observe the Memory usage through "Task Manager" in both cases. Once again, would be grateful if someone could explain.

Prerequisite ... create file "@ScriptDir & '\test.txt'" and deny yourself read/write rights on it.

; Prerequisite ... create file "@ScriptDir & '\test.txt'" and deny yourself read/write rights on it.
; File can be empty or have one line of TXT or whatever ...

Dim $t = 0, $f = 1
If MsgBox (262180, 'TEST', 'Do you wish to use function "_Test2"?') = 6 Then $f = 2
While 'TEST'
    Switch $f
        Case 1
            _Test1(@ScriptDir & '\test.txt')
        Case 2
            _Test2(@ScriptDir & '\test.txt')
    EndSwitch
    If @error AND MsgBox (262144, 'TEST', 'Prerequisite not met. Exiting.', 5) Then ExitLoop
    If $t = 1000 AND MsgBox (262180, 'TEST', 'Do you wish to STOP?') = 6 Then ExitLoop
    $t += 1
    If $t > 1000 Then $t = 0
    Sleep (5)
WEnd
Exit


Func _Test1($File = '')
    If $File = '' OR NOT FileExists ($File) Then Return SetError (1, 0, 'ERROR')
    $FileHandle = FileOpen ($File, 0)
        FileReadLine ($FileHandle, 1)
    FileClose ($FileHandle)
    Return SetError (0, 0, '')
EndFunc ;=>_Test1

Func _Test2($File = '')
    If $File = '' OR NOT FileExists ($File) Then Return SetError (1, 0, 'ERROR')
    FileReadLine ($File, 1)
    Return SetError (0, 0, '')
EndFunc ;=>_Test2
Edited by toofat

Share this post


Link to post
Share on other sites



I can replicate the problem under Win7 x64.

FileOpen is returning -1, indicating failure, but for some reason memory is used.

Obviously FileReadLine and FileClose will just plain fail with the invalid handle.

I can't find an open ticket on it, but it looks like a bug.

Share this post


Link to post
Share on other sites

friends....

How can i get text of the cursor position with out click on it

By using cursor position only

Share this post


Link to post
Share on other sites

Well yes, that is also what i think but a stupid bug ... More correct function of the two is not working ... Also, function _Test2() is the same as _Test1() but what if you wanted to do something like this ...

$FileHandle = FileOpen ($File, 2)
    FileWriteLine ($FileHandle, 1)
FileClose ($FileHandle)

OK, I will report it ...

Share this post


Link to post
Share on other sites

friends....

How can i get text of the cursor position with out click on it

By using cursor position only

first ... get your own post ... :unsure:


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

Also one more think, same thing happens if you do this

$FileHandle = FileOpen ($File, 0)
 If $FileHandle = -1 Then Return SetError (1, 0, 'ERROR')
 FileReadLine ($FileHandle, 1)
FileClose ($FileHandle)

So it is not only in the case of the wrong FileHandle. It is not "FileReadLine" that fails, it is FileOpen/FileClose combination ...

Share this post


Link to post
Share on other sites

Actually it's just FileOpen. As the other functions are not passed a valid handle, they do nothing.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0