Memory-hogging variables - swap to disk?

Discussion in 'C++' started by mrstephengross, Oct 27, 2006.

  1. Hi there... I've got a problem with memory usage. Specifically, I've
    got some data structures that grow to be really gigantic over the
    course of the program's execution. I'm wondering if there might be a
    way to ensure that the data structure is stored on disk rather than in
    memory. I realize that the OS is supposed to do this anyway for large
    programs, but in this case I'm wondering if it's possible to implement
    for a specific data structure. Consider the following class:

    // A class that stores results as they're generated:
    struct ResultsMgr
    {
    void addResults(const Results & results) { /* ... */ }
    void exportResults() { /* ... */ }
    };

    And let's say it's used like so:

    ResultsMgr mgr;
    for(AnalysisItr i = analyses.begin(); i != analyses.end(); ++i)
    {
    mgr.addResults(i->execute());
    }
    mgr.exportResults();

    In the above example, the ResultsMgr is only used (1) when results are
    ready to be added to it, and (2) at the end, to export the results
    somehow.

    Since the ResultsMgr is only used in a few places, it might make sense
    to let it be store on in a random-access file. Is there any way to do
    this in c++? Has anyone written such a utility?

    Thanks in advance,
    --Steve ()
     
    mrstephengross, Oct 27, 2006
    #1
    1. Advertising

  2. mrstephengross

    mlimber Guest

    mrstephengross wrote:
    > Hi there... I've got a problem with memory usage. Specifically, I've
    > got some data structures that grow to be really gigantic over the
    > course of the program's execution. I'm wondering if there might be a
    > way to ensure that the data structure is stored on disk rather than in
    > memory. I realize that the OS is supposed to do this anyway for large
    > programs, but in this case I'm wondering if it's possible to implement
    > for a specific data structure. Consider the following class:
    >
    > // A class that stores results as they're generated:
    > struct ResultsMgr
    > {
    > void addResults(const Results & results) { /* ... */ }
    > void exportResults() { /* ... */ }
    > };
    >
    > And let's say it's used like so:
    >
    > ResultsMgr mgr;
    > for(AnalysisItr i = analyses.begin(); i != analyses.end(); ++i)
    > {
    > mgr.addResults(i->execute());
    > }
    > mgr.exportResults();
    >
    > In the above example, the ResultsMgr is only used (1) when results are
    > ready to be added to it, and (2) at the end, to export the results
    > somehow.
    >
    > Since the ResultsMgr is only used in a few places, it might make sense
    > to let it be store on in a random-access file. Is there any way to do
    > this in c++? Has anyone written such a utility?


    You might be looking for some form of serialization, which allows you
    to store or transmit objects for later reconstruction. See these FAQs:

    http://www.parashift.com/c -faq-lite/serialization.html

    and check out Boost.Serialization:

    http://boost.org/libs/serialization/doc/index.html

    Cheers! --M
     
    mlimber, Oct 27, 2006
    #2
    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. Jas Shultz
    Replies:
    0
    Views:
    993
    Jas Shultz
    Dec 3, 2003
  2. thejeffross
    Replies:
    1
    Views:
    498
    Scott Allen
    May 26, 2005
  3. Niels Dekker (no reply address)

    What swap is called when using std::swap?

    Niels Dekker (no reply address), Jul 19, 2006, in forum: C++
    Replies:
    4
    Views:
    1,009
    Niels Dekker (no reply address)
    Jul 20, 2006
  4. Jan Hills
    Replies:
    1
    Views:
    688
    Jonathan N. Little
    Nov 28, 2007
  5. Scott Cole

    gserver hogging CPU

    Scott Cole, Jun 3, 2009, in forum: Ruby
    Replies:
    4
    Views:
    169
    Scott Cole
    Jun 3, 2009
Loading...

Share This Page