[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Using Hard Disk Space as Ram

Posted on 2004-10-21
6
Medium Priority
?
162 Views
Last Modified: 2010-04-01
Is there anyway in C++ to use the hard disk as RAM. Maybe even pre-allocate a block of space say like 2 - 5GB. If anyone can show me how or send me a tutorial it would help out tremendously.

I realize that here might be a slower access time but can anyone also point out any other ill effects that doing this may have with the code sample or tutorial.

Thanks in advance.
0
Comment
Question by:alfonzocarson
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 1

Expert Comment

by:gugario
ID: 12373310
What you wanna do is use binary file I/O, and pretty much have some kind of temp file in your directory which contains whichever memory information you want to store...

Check this page, it shows you how to insert data and access data at any position you want inside a file.

http://www.angelfire.com/country/aldev0/cpphowto/cpp_BinaryFileIO.html

This is just the File I/O part.  You can get a lot more complicated than that.. You could use a hash table to tell you where to write to, you could have page tables, etc, etc.  How you decide to implement it depends on what kind of data you are storing and for what.  If you want to give more detail about the data, maybe we can help you more.
0
 

Author Comment

by:alfonzocarson
ID: 12373365
gugario,

I'm trying to create a caching engine. But I don't want to load 500,000 records into RAM on the server. But I would like to have all of the benefits of memory resident data access. Will this tutorial get me there. There server will have 60+ GB of hard disk space on them, as they really aren't being used for anything other than a remoting service which makes calls to a SQL Database (on a separate machine).
0
 
LVL 30

Expert Comment

by:Axter
ID: 12374245
You can use map file API functions to map a file to memory.

What is your OS?

If you're using Windows, you can use the MapView API functions.
If you're using UNIX/Linux, you can use POSIX map file functions.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 30

Accepted Solution

by:
Axter earned 500 total points
ID: 12374275
See following link for file mapping example that works with Windows, UNIX, and Linux

http://code.axter.com/mapfile2mem.cpp

Also
http://code.axter.com/sharemem.h
0
 

Author Comment

by:alfonzocarson
ID: 12374443
Is this file going to be stored in memory or on the hard disk. I'm not up to speed on memory mapped files.
0
 
LVL 30

Expert Comment

by:Axter
ID: 12379195
>> Is this file going to be stored in memory or on the hard disk. I'm not up to speed on memory mapped files.

The file is stored on the hard disk, but you access the file data via a memory buffer.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
  Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question