Keeping a file in memory

Discussion in 'C Programming' started by G.D., Oct 25, 2004.

  1. G.D.

    G.D. Guest

    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.
    G.D., Oct 25, 2004
    #1
    1. Advertising

  2. G.D.

    Artie Gold Guest

    G.D. wrote:
    > 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

    --
    Artie Gold -- Austin, Texas

    "If you don't think it matters, you're not paying attention."
    Artie Gold, Oct 25, 2004
    #2
    1. Advertising

  3. G.D. wrote:

    > 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
    Allin Cottrell, Oct 26, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    15
    Views:
    450
    Dave Thompson
    Mar 27, 2006
  2. =?Utf-8?B?SnVsaWEgQg==?=

    Keeping datatable data in memory

    =?Utf-8?B?SnVsaWEgQg==?=, Oct 30, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    372
    =?Utf-8?B?SnVsaWEgQg==?=
    Oct 31, 2007
  3. Chris Binc
    Replies:
    3
    Views:
    103
    Robert Klemme
    Aug 16, 2006
  4. peter pilsl

    perl is keeping my memory

    peter pilsl, May 16, 2006, in forum: Perl Misc
    Replies:
    4
    Views:
    178
    peter pilsl
    May 17, 2006
  5. DartmanX
    Replies:
    2
    Views:
    118
    DartmanX
    Oct 12, 2005
Loading...

Share This Page