Keeping a file in memory

G

G.D.

Hi,

I'm using a third-party library which writes some useful
information into a file. In order to do so, I just have
to pass a file name to a library function and the file
gets written.

The problem is that I need the information that has been
written to the file immediately. I other words, the library
writes the info to a file (on disk) and my code reads this
file immediately afterwards, which makes writing the data
on the disk a waste of time.

I was wondering if there is a (ideally standardized and portable)
way to keep a file in memory indefinitly, where it presumably
can be read much faster?

Any help appreciated,

G.D.
 
A

Artie Gold

G.D. said:
Hi,

I'm using a third-party library which writes some useful
information into a file. In order to do so, I just have
to pass a file name to a library function and the file
gets written.

The problem is that I need the information that has been
written to the file immediately. I other words, the library
writes the info to a file (on disk) and my code reads this
file immediately afterwards, which makes writing the data
on the disk a waste of time.

I was wondering if there is a (ideally standardized and portable)
way to keep a file in memory indefinitly, where it presumably
can be read much faster?

Any help appreciated,

G.D.

There is not; any such facility, if it exists, would be platform specific.

HTH,
--ag
 
A

Allin Cottrell

G.D. said:
I'm using a third-party library which writes some useful
information into a file. In order to do so, I just have
to pass a file name to a library function and the file
gets written.

The problem is that I need the information that has been
written to the file immediately. I other words, the library
writes the info to a file (on disk) and my code reads this
file immediately afterwards, which makes writing the data
on the disk a waste of time.

I was wondering if there is a (ideally standardized and portable)
way to keep a file in memory indefinitly, where it presumably
can be read much faster?

If you want the information that is generated by the library
function _immediately_, the best solution is to have the library
write the info not to a file, but to a buffer -- a buffer to
which the clietnt program is passed a pointer. If you are not
in a position to make this modification to the library, you're
stuck with reading the file from disk.

As for "keeping a file in memory", _after_ is it read from disk,
any decent operating system will do this automagically, using
cache memory. Reading the file for the first time might be time-
consuming, if it is big file, but thereafter it will be read from
cache -- until some more pressing items fill the cache.

Allin Cottrell
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,539
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top