If we have large text file, which class object we can use to store all the contents of the file temporarily?
-
any text compatible container class will do more or less, different containers have different functionality, suitable for different usage scenarios, which you didn't specify
-
or you can use "QTemporaryFile":http://doc.qt.nokia.com/latest/qtemporaryfile.html
-
"store"? Store where? In memory? On disc? On the cloud perhaps?
And what is "temporarily"? For the runtime of your application, or for some longer period of time?Judging by your code fragment, I think you want to store the contents in-memory. Question is: why? The file is probably not going anywhere in the meantime, so why do want to keep all its (large) contents into memory? If you really need to, I guess QByteArray is the most efficient class to do it with. At least it won't use UTF-16 if the original file was ASCII or UTF-8 or some other 8-bit encoding. That should save you memory.
Another side note is: you already have the file in memory, because you are reading from a resource. Why do you insist in keeping another copy of the same file in memory too?
-
[quote author="Andre" date="1323250299"]"store"? Store where? In memory? On disc? On the cloud perhaps?
And what is "temporarily"? For the runtime of your application, or for some longer period of time?Judging by your code fragment, I think you want to store the contents in-memory. Question is: why? The file is probably not going anywhere in the meantime, so why do want to keep all its (large) contents into memory? If you really need to, I guess QByteArray is the most efficient class to do it with. At least it won't use UTF-16 if the original file was ASCII or UTF-8 or some other 8-bit encoding. That should save you memory.
Another side note is: you already have the file in memory, because you are reading from a resource. Why do you insist in keeping another copy of the same file in memory too?[/quote]
I want to keep all its (large) contents into memory because i want to search a specific data present in the file or not. Is their any other way of doing this without storing all the contents into the memory.
-
[quote author="Andre" date="1323250299"]Question is: why? The file is probably not going anywhere in the meantime, so why do want to keep all its (large) contents into memory? [/quote]
Agree!
I suspect you are going to scan/analyze the file content, and I guess it can be done iterating thru the content of the file instead of loading all the file into memory. With a few more details we could help you in achieving your aim. -
[quote author="pratik041" date="1323251213"]
I want to keep all its (large) contents into memory because i want to search a specific data present in the file or not. Is their any other way of doing this without storing all the contents into the memory.[/quote]
Sure there is!
You can just scan through the file bit by bit. That will be quite fast, as the file is actually in memory already (it is a resource, after all). -
[quote author="pratik041" date="1323251808"]So is reading line by line and stopping where i find the required data would be a better idea? [/quote]
If your aim is just to "grep" the file, yes. In the case the file is 2000 lines long and the word or data you are searching is in the first 10 lines you will avoid scanning all the other 1990 remaining lines. In the worst case, you data is at the end of the file and you will have to scan the whole.
By the way, the file is a resource, so aren't you already sure about its content? -
my file is something like this
@
.......................................
.......................................
.......................................
IDDLG_LOGIN OFI_DIALOGEX
BEGIN
...........................
........................
END
...........................
.............................
.
IDDLG_CONFIRM_OFI_DIALOGEX
BEGIN
...........................
...............................
END
.
.
@
Here suppose i have to find the text "IDDLG_LOGIN OFI_DIALOGEX" .
After that i have to do some string operation starting "BEGIN" to "END".
. -
[quote author="Andre" date="1323256622"]Yes.
Should be simple enough if you use a line-by-line parsing of your file. Did you try to create an implementation for that yet? Running into any specific issues?[/quote]Ya i have checked reading line by line to find some specific data it is working fine further i am trying some other operation on the data which i need.