Jump to content

Recommended Posts

Posted

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

  • Moderators
Posted

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

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

  • Moderators
Posted

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

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

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
×
×
  • Create New...