Sign in to follow this  
Followers 0
AZJIO

How to optimally write 200 values in .ini file

9 posts in this topic

#1 ·  Posted (edited)

1. If I write 200 values, the ini-file will be overwritten 200 times. This is not economical.

#include <GUIConstantsEx.au3>

; Свой реестр
$Ini = @ScriptDir & '\prog.ini'
$ifTrChMax = Number(IniRead($Ini, 'Setting', 'Max', '0'))

$hGui = GUICreate('My Program', 250, 260)
$iChMax = GUICtrlCreateCheckbox("Checkbox 1", 10, 10, 120, 20)
If $ifTrChMax Then GUICtrlSetState(-1, $GUI_CHECKED)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $iChMax
            $ifTrChMax = _ChReadToBool($iChMax)
        Case -3
            GUIDelete($hGui)
            _Exit()
    EndSwitch
WEnd

Func _ChReadToBool($iID)
    If BitAND(GUICtrlRead($iID), $GUI_CHECKED) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc   ;==>_ChReadToBool

Func _Exit()
    IniWrite($Ini, "Setting", "Max", $ifTrChMax)
    Exit
EndFunc   ;==>_Exit

2. If duplicate 2 status and check the difference, the number of entries will depend on the modified flags.

#include <GUIConstantsEx.au3>

; Свой реестр
$Ini = @ScriptDir & '\prog.ini'
$ifTrChMax = 0
$iniMax = Number(IniRead($Ini, 'Setting', 'Max', '0'))
$ifTrChMax = $iniMax

$hGui = GUICreate('My Program', 250, 260)
$iChMax = GUICtrlCreateCheckbox("Checkbox 1", 10, 10, 120, 20)
If $ifTrChMax Then GUICtrlSetState(-1, $GUI_CHECKED)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $iChMax
            $ifTrChMax = _ChReadToBool($iChMax)
        Case -3
            GUIDelete($hGui)
            _Exit()
    EndSwitch
WEnd

Func _ChReadToBool($iID)
    If BitAND(GUICtrlRead($iID), $GUI_CHECKED) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc   ;==>_ChReadToBool

Func _Exit()
    ; Если изменилось с момента чтения ini-файла, то записать новое значение
    If $ifTrChMax <> $iniMax Then IniWrite($Ini, "Setting", "Max", $ifTrChMax)
    Exit
EndFunc   ;==>_Exit

3. If before exiting the program to read the ini-file into an array and make the upgrade in memory, the overwritten will be executed one time. (>IniVirtual.au3)

#include <GUIConstantsEx.au3>
#include <IniVirtual.au3>

; Свой реестр
$Ini = @ScriptDir & '\prog.ini'
$ifTrChMax = Number(IniRead($Ini, 'Setting', 'Max', '0'))

$hGui = GUICreate('My Program', 250, 260)
$iChMax = GUICtrlCreateCheckbox("Checkbox 1", 10, 10, 120, 20)
If $ifTrChMax Then GUICtrlSetState(-1, $GUI_CHECKED)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case $iChMax
            $ifTrChMax = _ChReadToBool($iChMax)
        Case -3
            GUIDelete($hGui)
            _Exit()
    EndSwitch
WEnd

Func _ChReadToBool($iID)
    If BitAND(GUICtrlRead($iID), $GUI_CHECKED) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc   ;==>_ChReadToBool

Func _Exit()
    Local $a_ini_Main2D, $hFile, $s_ini_Text
    $s_ini_Text = FileRead($Ini)
    $a_ini_Main2D = _IniVirtual_Initial($s_ini_Text)
    _IniVirtual_Write($a_ini_Main2D, 'Setting', 'Max', $ifTrChMax)
    $s_ini_Text = _IniVirtual_Save($a_ini_Main2D)
    $hFile = FileOpen($Ini, 2)
    FileWrite($hFile, $s_ini_Text)
    FileClose($hFile)
    Exit
EndFunc   ;==>_Exit

I chose the last option. There are other opinions?

I know that the registry is better, but I'm taking into account the transfer on a flash drive.

Edited by AZJIO

Share this post


Link to post
Share on other sites



maybe IniWriteSection could be more appropriate instead of IniWrite


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

He writes with one stream?

Maybe I should not bother.

(1000 launch) * (20-40 parameters) = (20 000 rewrite)

5 KB * 20 000 = 100 MB

Some programs can only be configured when you first start. Or 10 starts, one of them an rewrite in the ini-file.

I want to decide on the choice of algorithm, then not to remake.

Share this post


Link to post
Share on other sites

Why not manually create the ini in the form of an array or variable and then transfer that to a file directly? You can still use a normal iniread but at least the write would be a single process to transform the variable to saved file.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I think AZJIO want to use that in an intensive concurrent read / write environment where many instances of that task will run on the same ini. (or not?.... in that form all tasks access the same key within the ini)
... in that case I also would take in consideration the use of SQLite as in >this jchd's example for intensive concurrent r/w acces to a database

Edited by PincoPanco

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

>INI File Processing Functions work for real by reference, has not the speed of AutoIt INI Function, but it is quite fast and has no limits and more options

 

Ciao.

Edited by DXRW4E

apps-odrive.pngdrive_app_badge.png box-logo.png new_logo.png MEGA_Logo.png

Share this post


Link to post
Share on other sites

SSD Write Limit

@Morthawt

See item 3. This is what you're saying.

@PincoPanco

No. I just do not want to write something that does not require writing. Ideal logic to do only what is required. Flash card slower and worn more out.

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  
Followers 0