Physical access to a file [IniRead vs FileRead]

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kidbit
Posts: 168
Joined: 02 Oct 2013, 16:05

Physical access to a file [IniRead vs FileRead]

29 Oct 2013, 16:48

How does IniRead in ahk actually work? Does it attempt to access the file every time the IniRead is invoked? Or does it actually cache the whole file upon first IniRead and later calls to the cache?

I'm thinking of re-writing my existing script so that it would read the settings.ini once via FileRead, but since that file is INI formatted - I'd need to write functions to work with a variable like with a file.
But I'm not sure if that's all worth the efforts.
question := (2b) || !(2b) © Shakespeare.
Guest

Re: Physical access to a file [IniRead vs FileRead]

29 Oct 2013, 17:32

As far as I know each IniRead will indeed access the file each time, so if you have many read/writes and a large INI it might be worth the effort. There are several INI libraries posted on the other forum which will take care of all your problems, there are those working with variables and those that return an object, just use what you think is best.
kidbit
Posts: 168
Joined: 02 Oct 2013, 16:05

Re: Physical access to a file [IniRead vs FileRead]

30 Oct 2013, 13:54

I've counted how many times I use iniread/iniwrite in my script with the account of the probability of each of them to actually get executed and it appears that it's quite a small number.
However, quite much of the script's code describes how to parse the iniRead data, I have to manually use it to fulfill the arrays.
Verdlin thanks for that script, but seems like it'd be an overkill for my script.
I think I'll stick to IniWrite/Read, but will optimize them.
question := (2b) || !(2b) © Shakespeare.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Physical access to a file [IniRead vs FileRead]

02 Nov 2013, 08:50

You can also create a binary file with the File Object.
Recommends AHK Studio
kidbit
Posts: 168
Joined: 02 Oct 2013, 16:05

Re: Physical access to a file [IniRead vs FileRead]

02 Nov 2013, 10:04

nnnik
could you demonstrate how to do that?
question := (2b) || !(2b) © Shakespeare.
User avatar
nnnik
Posts: 4500
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: Physical access to a file [IniRead vs FileRead]

02 Nov 2013, 10:29

Code: Select all

savesettingstofile(filename)
file:=fileopen(filename,"rw")
S:=""
A:={}
File.rawread(s,100)
A.setting1:=Numget(s,0,"uint")
A.setting2:=numget(s,4,"float")
A.setting3:=stringget(&s+8,92,"utf-8")
}
Recommends AHK Studio
Wade Hatler
Posts: 60
Joined: 03 Oct 2013, 19:49
Location: Seattle Area
Contact:

Re: Physical access to a file [IniRead vs FileRead]

02 Nov 2013, 11:30

INI files are read every time but the drive caches the file so they're quite fast. I've used them for years with quite a few variables and even timed it to make sure it was ok. Don't have the numbers still, but it's easy to make a little timer to test them with A_TickCount.

If you want to bulk process them, an easy way is to read the whole [Section] with IniRead with a blank parameter for the value. Then split the result with a RegEx, or use Loop, Parse to work each line. I do that then I don't know in advance what the value names are or when i'm searching for values on the right of the =.

I have an example I could post if you're interested.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 350 guests