[Interest] Simple doubt on file i/o

Mandeep Sandhu mandeepsandhu.chd at gmail.com
Thu Jun 27 09:57:01 CEST 2013


On Thu, Jun 27, 2013 at 12:58 PM, Arne Dirks <arne.dirks at iathh.de> wrote:

> On 06/27/2013 08:56 AM, Mandeep Sandhu wrote:
> > get(key):
> > * Open the file in Read-Only mode.
> > * Parse the data and prepare a QMap of the key-value pairs.
> > * Close the file
> > * Return the value for the key
> >
> > set(key, value):
> > * Open the file in Read-Only mode.
> > * Parse the data and prepare a QMap of the key-value pairs.
> > * Close the file
> > * Open the file in Write-Only & Truncate mode
> > * Insert the new key-value in the map
> > * Write the map
> > * Close the file
>
> Is there a reason why you read the file every time you get/set
> something? Couldn't you read the file once during application startup,
>

Yes, there's a reason. The data fetched by the app is via a _relatively_
expensive network handshake with a remote service. The data returned is not
much and hence I thought it better to write it the moment i receive it.
There's a possibility that the app might be closed/crash due to some
external factors and if I have it in memory (as a map) then I'd have to the
network op all over again.

-mandeep



> store the data in a map and only write it out again when your
> application terminates, provided anything has changed at all?
> arne
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130627/3a5502e9/attachment.html>


More information about the Interest mailing list