I am just writing a program in c++ (Borland c++ builder)
In my program, i want to read from/write to an .ini file. I have some experience for using .ini file's in c++ but i was wondering about the different way's to use TIniFile.
For example, i have just tested two differend methods.
Methode 1
1 2 3 4 5 6 7 8 9 10 11
|
#include <inifiles.hpp>
#include "Unit1.h"
//---------------------------------------------------------------------------
void __fastcall TForm1::btnIniClick(TObject *Sender)
{
TIniFile *MyIni = new TIniFile(ChangeFileExt("dir\\file", ".ini" ) );
MyIni -> WriteString ("Section1", "Item1", "value");
MyIni -> WriteInteger("Section2", "Item1", 35);
delete ini;// what will happen if I don't delete "ini" ?
}
|
Methode 2
1 2 3 4 5 6 7 8 9 10
|
#include <inifiles.hpp>
#include "Unit1.h"
TIniFile *MyIni = new TIniFile(ChangeFileExt("dir\\file", ".ini" ) );
//---------------------------------------------------------------------------
void __fastcall TForm1::btnIniClick(TObject *Sender)
{
MyIni -> WriteString ( "Section1", "Item1", "value");
MyIni -> WriteInteger("Section2", "Item1", 35);
}
|
for sure, the difference between the two methods; method 1 is like all the example's. create/open -> write or read -> delete. all in the same function
method 2 create/open at start of program, somewhere else in the code write or read. never delete, and no need to create/open the file every time
i just checked if there is any difference by running the two different methods, but also by method 2 the program is closing the file after all read/write actions, and also by method 2, the program is not using more memory after each read/write action.
can someone tell me the reason for delete the ini each time?
Thanks in advance