Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Memory-hogging variables - swap to disk?

Reply
Thread Tools

Memory-hogging variables - swap to disk?

 
 
mrstephengross
Guest
Posts: n/a
 
      10-27-2006
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 ((E-Mail Removed))

 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      10-27-2006
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-lit...alization.html

and check out Boost.Serialization:

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

Cheers! --M

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to swap between two variables? RoseVeera Case Modding 0 10-13-2011 08:52 AM
Put variables into member variables or function variables? tjumail@gmail.com C++ 9 03-23-2008 04:03 PM
What swap is called when using std::swap? Niels Dekker (no reply address) C++ 4 07-20-2006 08:44 PM
Swap DOM objects in / out to object variables? sneill@mxlogic.com Javascript 13 01-28-2005 11:56 PM
How to swap plugins/extensions between 2 computer / various version of Mozilla Firefox? Chaos Master Firefox 0 07-10-2004 05:00 AM



Advertisments