SputnikDX wrote:I know about FileRead, but it has an arbitrary limit of 1GB,
No, it does not.
FileRead wrote:*m1024: If this option is omitted, the entire file is loaded unless there is insufficient memory, in which case an error message is shown and the thread exits (but Try can be used to avoid this). Otherwise, replace 1024 with a decimal or hexadecimal number of bytes. If the file is larger than this, only its leading part is loaded. Note: This might result in the last line ending in a naked carriage return (`r) rather than `r`n.
To load a 1.5GB file entirely into memory, you will need at least 1.5GB of available virtual memory (across RAM and page file)
and a
contiguous block of 1.5GB unused virtual address space. AutoHotkey 32-bit is not "large address aware" and therefore only has 2GB of address space at its disposal. The largest
contiguous block of free address space depends on where any other allocations were made within that 2GB space. There might not be a 1.5GB contiguous block even if the process is using <10 MB.
If you are using AutoHotkey Unicode 32-bit and the file is
not encoded with UTF-16, it is very likely you will need roughly twice the amount of memory, because each character is twice the size (16-bit in memory vs 8-bit in the file).
Exaskryz wrote:FileReadLine, var, C:\Files\text.txt, % A_Index*10000
Very bad idea. In order to read and return line 10000, FileReadLine has to read and discard the first 9999 lines. So the loop would read 10000 lines, then 20000 lines (including the first 10000
again) and so on.
wolf_II wrote: f.Write(A_Index "`n`r")
That will write an empty line after every line, using inconsistent line endings. I'm pretty sure you meant to write
"`r`n"...
ignore := StrReplace(BigVar, "`n`r", "", Count)
If you use
"`n", that would work for files with either of the line endings common on Windows: "`n" or "`r`n". Putting aside the transposed characters, this method relies on the entire file fitting in memory.
Shadowpheonix's solution seems like it should be the most efficient one.
However, depending on what you're doing, it may be more efficient to read and process a larger chunk of the file at a time, rather than a line at a time.