Using Hard Disk Space as Ram

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.
alfonzocarsonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gugarioCommented:
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
alfonzocarsonAuthor Commented:
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
AxterCommented:
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
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

AxterCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
alfonzocarsonAuthor Commented:
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
AxterCommented:
>> 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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.