kiboost Posted February 3, 2011 Share Posted February 3, 2011 Hi, I'm doing some stringreplace in a file, and having no problem with file less than 500Ko, when files reach 900Ko/1Mo, my result file get errors. It cut some portions in some lines randomely. On a 50 000 line xml, hard to exactly see what happend, but it happens. Here is the code I use (part of) $compfile = FileOpen($rw_comp, 0) $compfile = FileRead($compfile) ; some StringRegExpReplace there ! $hFile = FileOpen($rw_comp, 2) FileWrite($hFile, $compfile) FileClose($hFile) So, did anyone heard of some size limitation for these functions ? Or anything could cause that ? Thanks Kib Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2011 Moderators Share Posted February 3, 2011 kiboost,The problem is that the file is too large to be read into memory in one piece and have a second amended copy as well. I would suggest looking at _WinAPI_SetFilePointer in conjunction with _WinAPI_ReadFile - that way you can get manageable sized chunks into memory to amend. Write the amended text to a temporary file as you progress and then rewrite the main file once everything is done. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kiboost Posted February 3, 2011 Author Share Posted February 3, 2011 Thks Melba ! I changed my code to this : only one fileopen $compfileopen = FileOpen($rw_comp, 2) $compfile = FileRead($compfileopen ) ; some StringRegExpReplace there ! FileWrite($compfileopen, $compfile) FileClose($compfileopen) Now it works. I'm on x64 windows7 with 4Go of ram, so is it possible to reach such limit ? Or did it was just the two fileopen that caused this ? In case it happens again later with even larger files (10Mo should be the maximum). Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 3, 2011 Moderators Share Posted February 3, 2011 kiboost,Sooner or later you will run into the memory problem - it all depends on what else is trying to use it at the time. Reading seriously large files into memory is always fraught with danger - that is why "proper" applications use the "chunk" technique I mentioned above and fool the user into thinking everything is in memory at once. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
kiboost Posted February 4, 2011 Author Share Posted February 4, 2011 thanks Melba, you are totally right pointe me in good method direction, and thanks for that. I will definitely have a look at this method to implement it soon. Thanks for your time on this board, allways very pertinent comment. Kib Win7 pro x64. scripts compiled to x64. - Autoit v3.3.6.1 | Scite 1.79 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now