473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Memory-hogging variables - swap to disk?

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 (mr************@hotmail.com)

Oct 27 '06 #1
1 1616
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

Oct 27 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
by: xixi | last post by:
hi, we are using db2 udb v8.1 for windows, i have changed the buffer pool size to accommadate better performance, say size 200000, if i have multiple connection to the same database from...
7
by: Jon Trickey | last post by:
We migrated to 8.1 from 7.2 this weekend. Everything ran ok over the weekend, but we have a light user load then (about 200 users.) Today when we had close to 600 users connecting and running...
8
by: ranjeet.gupta | last post by:
Dear All Is the Root Cause of the Memory corruption is the Memory leak, ?? suppose If in the code there is Memory leak, Do this may lead to the Memory Corruption while executing the program ? ...
62
by: ivan.leben | last post by:
How can I really delete a preloaded image from memory/disk cache? Let's say I preload an image by creating an Image object and setting its src attribute to desired URL: var img = new Image();...
94
by: smnoff | last post by:
I have searched the internet for malloc and dynamic malloc; however, I still don't know or readily see what is general way to allocate memory to char * variable that I want to assign the substring...
3
by: Jim Land | last post by:
Jack Slocum claims here http://www.jackslocum.com/yui/2006/10/02/3-easy-steps-to-avoid-javascript- memory-leaks/ that "almost every site you visit that uses JavaScript is leaking memory". ...
1
by: Nick Craig-Wood | last post by:
I've been dumping a database in a python code format (for use with Python on S60 mobile phone actually) and I've noticed that it uses absolutely tons of memory as compared to how much the data...
5
by: kumarmdb2 | last post by:
Hi guys, For last few days we are getting out of private memory error. We have a development environment. We tried to figure out the problem but we believe that it might be related to the OS...
1
by: Jean-Paul Calderone | last post by:
On Tue, 22 Apr 2008 14:54:37 -0700 (PDT), yzghan@gmail.com wrote: The test doesn't demonstrate any leaks. It does demonstrate that memory usage can remain at or near peak memory usage even after...
5
by: cham | last post by:
Hi, I am working on c++ in a linux system ( Fedora core 4 ), kernel version - 2.6.11-1.1369_FC4 gcc version - 4.0.0 20050519 ( Red Hat 4.0.0-8 ) In my code i am creating a vector to store...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.