Jump to content
Sign in to follow this  
Jon

AutoIt v3.3.13.12 Beta

Recommended Posts

Jon

File Name: AutoIt v3.3.13.12 Beta

File Submitter: Jon

File Submitted: 28 Jul 2014

File Category: Beta



3.3.13.12 (28th July, 2014) (Beta)
AutoIt:
- Fixed: Memory leak with rewritten array code.
- Fixed: Dim performance regression.



Click here to download this file

  • Like 1

Share this post


Link to post
Share on other sites
FaridAgl

Thanks Jon, there is no memory leak while using DllStructs anymore.

Also the test script (Which I posted in the previous thread) runs about 40% faster than the current stable, and about 75% faster than the previous beta.

Share this post


Link to post
Share on other sites
jvanegmond

How should we go about iterating maps keys and values at the same time?

I've found this bit of code (thanks Melba23) which has a few drawbacks.:

Func _DoSomething($mMap)
    If Not IsMap($mMap) Then Return SetError(1, 0, -1)

    Local $aKeys = MapKeys($mMap)
    If @error Then Return SetError(2, 0, "")
    
    For $i = 0 To UBound($aKeys) - 1
        $vValue = $mMap[$aKeys[$i]]

The amount of code necessary to check errors and iterate the map obscures the actual purpose of the function. 

The error checks on IsMap and MapKeys are redundant: Either you do not receive a map in $mMap and IsMap fails or you do receive a map and MapKeys will never fail. So in practice, to write good code, you either have to have MapKeys (which can error) not error-checked, or you're going to omit the type-checking code. Either solution isn't really very good because it's not consistent with other data types.

And obviously: $mMap[$aKeys[$i]] is somewhat unreadable.

I would much prefer to write this:

Func _DoSomething($mMap)
    If Not IsMap($mMap) Then Return SetError(1, 0, -1)
    
    For $vKey In $mMap
        $vVal = $mMap[$vKey]

(Currently $vKey actually holds $vVal and there is no way to get $vKey from there) Or even:

Func _DoSomething($mMap)
    If Not IsMap($mMap) Then Return SetError(1, 0, -1)
    
    For $vKey, $vVal In $mMap

Both look very sexy, with the latter having my preference. We want to avoid lookups in our multi-million elements map.

Apologies if I'm simply misinformed and we can do what I described in my last example.

Edited by Manadar

Share this post


Link to post
Share on other sites
jvanegmond

Performance seems to drop-off fairly quickly when the map grows in size. To add the first 1000 elements to a map it takes approximately 8ms, but when the map already had 100K elements in it, it took about 3 seconds. This seems to be more-or-less linearly. If it's implemented as a hash table, the insertion performance should be O(1) so something is definitely up.

Here's the script I used to check this. It can't be the lexer/parser so it must be the map.

Local $mMap[]

$t = TimerInit()
For $n = 0 To 100000
    $mMap[$n] = $n
    If Mod($n, 1000) = 0 Then
        ConsoleWrite(TimerDiff($t) & "ms: #" & $n & @CRLF)
        $t = TimerInit()
    EndIf
Next

Share this post


Link to post
Share on other sites
jvanegmond

It's just a list for now. Can always improve it when the syntax is sorted.

Ok so the slowdown is probably because it tries to find an existing key same as the one you're trying to insert, which is O(n) time complexity.

 

Does this not work like you want?

For $vKey In MapKeys($mMap)
    $vVal = $mMap[$vKey]
Next

It does. Though I admit it hadn't crossed my mind because of MapKeys error checking. The main goal was to establish good habit within the community when iterating map key/values and that's been done I think.

Share this post


Link to post
Share on other sites
Zedna
For $vKey In MapKeys($mMap)
    $vVal = $mMap[$vKey]
Next

 

I proposed this small example for adding as example in helpfile for manual iterating through Maps (private forum link)

but Melba didn't agree with adding it :-(

As you can see this example is very important and should be definitely added into helpfile.

Edited by Zedna
  • Like 1

Share this post


Link to post
Share on other sites
guinness

Zedna your code suggestion doesn't match that of what Jon posted. Melba23 was correct to reject as keys should be iterated using the in-built function.

Edit: I saw your second link.

Edited by guinness

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
eukalyptus

"Expected a variable in user function call." - error if you pass a map´s value to a function as byref or const byref:

#AutoIt3Wrapper_Version = B
#AutoIt3Wrapper_Run_Au3Check=N

#include <WinAPI.au3>

$tString = DllStructCreate("wchar Text[128];")
$tString.Text = "Abcdefg"

Global $mMap[]
$mMap.String = DllStructCreate("wchar Text[128];")
$mMap.String.Text = "Abcdefg"

Global $iLen
$iLen = _WinAPI_StringLenW($tString);<- working
ConsoleWrite("> Len: " & $iLen & @CRLF)

$iLen = DllCall("kernel32.dll", "int", "lstrlenW", "struct*", $mMap.String)[0];<- working
ConsoleWrite("> Len: " & $iLen & @CRLF)

$iLen = _WinAPI_StringLenW($mMap.String);<- not working
ConsoleWrite("> Len: " & $iLen & @CRLF)

Share this post


Link to post
Share on other sites
water

Is the "Remarks" section in FileSetEnd correct`? Because it has the same content as FileSetPos. There is no "Origin" parameter in FileSetEnd so it looks like a copy/paste error to me.

 

Remarks Include Constants.au3 in your script to use the symbolic name in parentheses to specify the origin.
Using FileSetPos() it is possible to both read and write to the same file. When attempting to read and write to the same file, always call FileFlush() between each write and read operation.
Moving the pointer to the middle of the data can be used to overwrite data.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-12-03 - Version 1.4.11.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
guinness

This should be removed and is on my todo list, but currently I don't have svn. I should be able to update this weekend.


UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Jon

"Expected a variable in user function call." - error if you pass a map´s value to a function as byref or const byref:

Passing dot notation by reference isn't implemented yet. For now you need to use map["String"]

The dot notation is proving to be very ambiguous and hard to parse correctly past a single element. Especially trying to work out what works when swapping data types. I might have to seriously limit it to make it work sensibly.

Share this post


Link to post
Share on other sites
Zedna

There is no example for new FileSetEnd() function
Here is one example demonstrating expanding/truncating size of file using FileSetEnd()

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local Const $sFilePath = @TempDir & "\FileSetEnd.txt"

    ; create file 6 bytes in size
    FileDelete($sFilePath)
    FileWrite($sFilePath,'abc123')
    MsgBox($MB_SYSTEMMODAL, FileGetSize($sFilePath), FileRead($sFilePath)) ; 6 / abc123

    ; expand size of file to 9 bytes but don't write any data to expanded area
    $hFileOpen = FileOpen($sFilePath, $FO_APPEND)
    FileSetPos($hFileOpen, 9, $FILE_BEGIN)
    FileSetEnd($hFileOpen)
    FileClose($hFileOpen)
    MsgBox($MB_SYSTEMMODAL, FileGetSize($sFilePath), FileRead($sFilePath)) ; 9 / abc123

    ; write data to expanded area (more than size of expanded area) so size of file will auto expand to 12 bytes (6+6)
    $hFileOpen = FileOpen($sFilePath, $FO_APPEND)
    FileSetPos($hFileOpen, 6, $FILE_BEGIN)
    FileWrite($hFileOpen,'def456')
    FileClose($hFileOpen)
    MsgBox($MB_SYSTEMMODAL, FileGetSize($sFilePath), FileRead($sFilePath)) ; 12 / abc123def456

    ; truncate size of file to 9 bytes
    $hFileOpen = FileOpen($sFilePath, $FO_APPEND)
    FileSetPos($hFileOpen, 9, $FILE_BEGIN)
    FileSetEnd($hFileOpen)
    FileClose($hFileOpen)
    MsgBox($MB_SYSTEMMODAL, FileGetSize($sFilePath), FileRead($sFilePath)) ; 9 / abc123def

    FileDelete($sFilePath)
EndFunc   ;==>Example

EDIT:

In rekmarks can be mentioned that current position for FileSetEnd() can be changed by FileSetPos()

In rekmarks can be mentioned that for expanding/truncating of existing files with preserved content have to be used mode $FO_APPEND in FileOpen()

Edited by Zedna

Share this post


Link to post
Share on other sites
guinness

Zenda,

I was going to commit this example instead.

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    ; Create a constant variable in Local scope of the filepath that will be read/written to.
    Local Const $sFilePath = @TempDir & "\FileSetEnd.txt"

    ; Open the file for writing (overwrite the file) and store the handle to a variable.
    Local $hFileOpen = FileOpen($sFilePath, $FO_OVERWRITE)
    If $hFileOpen = -1 Then
        MsgBox($MB_SYSTEMMODAL, "", "An error occurred when writing the file.")
        Return False
    EndIf

    ; Write data to the file using the handle returned by FileOpen.
    FileWriteLine($hFileOpen, "Line 1")
    FileWriteLine($hFileOpen, "Line 2")
    FileWriteLine($hFileOpen, "Line 3")

    ; Flush the file to disk.
    FileFlush($hFileOpen)

    ; Now, adjust the position to the beginning.
    FileSetPos($hFileOpen, 0, $FILE_BEGIN)

    ; Check file position and try to read contents for current position.
    MsgBox($MB_SYSTEMMODAL, "", "Position: " & FileGetPos($hFileOpen) & @CRLF & "Data: " & @CRLF & FileRead($hFileOpen))

    ; Write data to the file using the handle returned by FileOpen.
    FileWriteLine($hFileOpen, "Line 4")
    FileWriteLine($hFileOpen, "Line 5")
    FileWriteLine($hFileOpen, "Line 6")

    ; Now, adjust the position to the beginning.
    FileSetPos($hFileOpen, 0, $FILE_BEGIN)

    ; Check file position and try to read contents for current position.
    MsgBox($MB_SYSTEMMODAL, "", "Position: " & FileGetPos($hFileOpen) & @CRLF & "Data: " & @CRLF & FileRead($hFileOpen))

    ; Now, adjust the position to the beginning.
    FileSetPos($hFileOpen, 0, $FILE_BEGIN)

    ; Set the end of the file at the current position.
    FileSetEnd($hFileOpen)

    ; Check file position and try to read contents for current position. The contents have been destroyed.
    MsgBox($MB_SYSTEMMODAL, "", "Position: " & FileGetPos($hFileOpen) & @CRLF & "Data: " & @CRLF & FileRead($hFileOpen))

    ; Close the handle returned by FileOpen.
    FileClose($hFileOpen)

    ; Delete the temporary file.
    FileDelete($sFilePath)
EndFunc   ;==>Example

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Share this post


Link to post
Share on other sites
Mat

Example could potentially cause permanent changes to the system (if the user is already using a file called FileSetEnd.txt in the temp directory...), why not use the _TempFile function?

Yours Truly,

An Example Nazi

:P

Share this post


Link to post
Share on other sites
Richard Robertson

I think that it would be easier to remove the dot notation in the first place unless you actually want to implement objects. There's nothing difficult or ugly about the index operator.

Share this post


Link to post
Share on other sites
jchd

That's a good argument indeed.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
Zedna

@guinness

I think that my example (for FileSetEnd) is much better because my example is more focused on FileSetEnd() and demonstrate more expanding/truncating size of file

and your example is much bloating with FileSetPos/FileGePos and only one FileSetEnd()

Edited by Zedna

Share this post


Link to post
Share on other sites
Zedna

Example could potentially cause permanent changes to the system (if the user is already using a file called FileSetEnd.txt in the temp directory...), why not use the _TempFile function?

 

temp directory is for temporary files which can be ovewritten/deleted without harming of system.

Important files should always be stored elsewhere than in Temp directory.

Edited by Zedna

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  

×