473,855 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I create a Ram Disk within C/C++ program?

Tom
I'd greatly appreciate advice and code snippets on how to create a ram
disk within a C/C++ program.

I also need to be able to determine the free space.

Thanks in advance for any help.
Aug 28 '06
34 29928
Tom schrieb:
I have revisited creating a very large array for holding raw data
which is used in an iterative optimization algorithm. The purpose of
the large array is to eliminate the slow hard disk reads and increase
program throughput. On an older machine (Win2000, Visual C++ 6.0, 256
M ram) when I compile with a huge array I get the following warning:

=============== =============== =============== =============== =========
warning LNK4084: total image size 343744512 exceeds max (268435456);
image may not run
=============== =============== =============== =============== =========
Thats a linker error. What did you do to the linker?

Just don't use a filescope array, try to malloc() a block of memory, or if
malloc() can't handle that large blocks, allocate multiple chunks of
smaller memory blocks.

You really don't need a ramdisk.

--
Thomas
Aug 29 '06 #31
Nick Keighley wrote:
Kenny McCormack makes silly remarks on comp.lang.c just to get a
reaction. This is known as "trolling"; it is best to ignore him.
I agree.

--
pete
Aug 29 '06 #32
Tom
On Wed, 30 Aug 2006 00:18:26 +0200, "Thomas J. Gritzan"
<Ph************ *@gmx.dewrote:
>Tom schrieb:
>I have revisited creating a very large array for holding raw data
which is used in an iterative optimization algorithm. The purpose of
the large array is to eliminate the slow hard disk reads and increase
program throughput. On an older machine (Win2000, Visual C++ 6.0, 256
M ram) when I compile with a huge array I get the following warning:

============== =============== =============== =============== ==========
warning LNK4084: total image size 343744512 exceeds max (268435456);
image may not run
============== =============== =============== =============== ==========

Thats a linker error. What did you do to the linker?

Just don't use a filescope array, try to malloc() a block of memory, or if
malloc() can't handle that large blocks, allocate multiple chunks of
smaller memory blocks.

You really don't need a ramdisk.
From Tom to Tom --

Thanks!

My linker is just in the default setting mode. I have never adjusted
it. I write "console" apps.

I need to wait until my current run finishes (another painful 28
hrs)... but as soon as it does I will trying to malloc() my way to
success.

If this works ... I will be thrilled!

Aug 30 '06 #33

"Tom" <Th********@ear thlink.netwrote in message
news:bt******** *************** *********@4ax.c om...
I'd greatly appreciate advice and code snippets on how to create a ram
disk within a C/C++ program.

I also need to be able to determine the free space.

Thanks in advance for any help.
To create ramdisk

unsigned char * ramdisk = malloc(1024 * 64);

if that proves too small

temp = realloc(ramdisk , 1024 * 128);
if(temp)
ramdisk = temp;
else
/* tell user you are very sorry but there is no more memory */

Now we can implement
int ramputc(int ch)
{
if( ch == EOF)
/* do you wnat to handle this ? */
if(len < capacity)
ramdisk[len++] = (unsigned char) ch;
else
return EOF;
return 0;
}

ramfputs, ramfwrite and so on can be built on top of ramputc.

What you cannot do is associate your ramdisk with a C FILE *. Very stupid
restriction, I know. In C++ you can theoretically override the IoStream
classes, but rather you than me.

--
www.personal.leeds.ac.uk/~bgy1mm
freeware games to download.
Sep 1 '06 #34
"Tom" writes:
I'd greatly appreciate advice and code snippets on how to create a ram
disk within a C/C++ program.

I also need to be able to determine the free space.
I haven't followed this thread, so this may just repeat what someone has
already said.

In order to create a Ram Disk on a modern system you need the ability to
"nail" some space in the RAM caching mechanism provided by the OS. Lacking
such a capability, the OS is free to roll the contents of what you think is
a RAM address out to disk.

The OS people have already done what they think is a decent job of handling
both internal and external memory via. RAM caching and disk caching.
Anything you do is going to have to fight the mechanisms already in place.
The ability to nail is, IMO, a requisite of an adult OS, which should allow
some real time usage on the system intermixed with the ordinary flow of
lower priority jobs. IOW, the ability might be offered on something like,
say, Windows NT but not on the ordinary line of OSes. I am only familiar
with one disk caching system, and it did not provide an ability to either
nail or tack - where a tack is the short term equivalent of a nail.
Sep 2 '06 #35

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

Similar topics

9
1793
by: codecraig | last post by:
Hi, Is there a way to create one .exe using py2exe (or some other extension/utility that can do it)? Basically i want to generate one .exe that contains everything my python app needs to run instead of having a .exe, some .zips, etc. thanks
5
7593
by: Yasaswi Pulavarti | last post by:
does a command like, db2 drop table tabschema.tabname when run from the Aix prompt reclaim the disk space? Are there any other options? How can we make sure the disk space is reclaimed? Thanks, Yasaswi
7
8878
by: dog | last post by:
I've seen plenty of articles on this topic but none of them have been able to solve my problem. I am working with an Access 97 database on an NT4.0 machine, which has many Access reports. I want my users to be able to select a report, click on a command button on a form, which will then automatically create the report as a pdf file and save it to the user's machine. I am using Adobe Acrobat (5.0 I think) and have Adobe Distiller as a
4
1284
by: ad | last post by:
We can use System.IO namespace to create a directory in win-base program. But when I want to create a directory in the server with web-base program, System.IO namespace can't work? How can I do that?
6
1241
by: David Thielen | last post by:
Hi; On my home computer (work computer is fine), when I create a new ASP .NET project, it takes minutes (no exageration) for it to create the project. It is paused forever on a dialog that says something like connectiong to localhost/project. And when I start the debugger, it takes about 20 seconds for the page to come up.
11
2463
by: VJ | last post by:
I have these functions in my application. FileInfo.CopyTo DirectoryInfo.Create File.Copy Directory.Create
2
5496
by: yxq | last post by:
Hello I want to create and delete the folder share, i found that it is ok for generic folder, but it does not work for Root directory(i.e c:\, d:\) The code **************************************************** Dim mc As New ManagementClass("Win32_Share") Dim mo As ManagementObject Dim inParams As ManagementBaseObject Dim outParams As ManagementBaseObject
8
4238
by: Foodbank | last post by:
Hi, Has anyone ever hashed a text file to disk before? I'm trying to convert an in-memory hash to disk hash and I can't find any relevant information to help me. Also, I'd like to use lseek, read, write, and fd if anyone is familiar with them. Any info would be greatly helpful. Thanks, James
2
1877
by: marco.minerva | last post by:
Hi all! Within my PHP page (on an Apache webserver), I must call a shell program that saves a file to disk. The program is executed correctly, but nothing is saved; I think this is a permission problem. I can't modify the program, so there is a way to solve the problem? Thanks in advance. -- Marco Minerva, marco.minerva@gmail.com
0
9903
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9754
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10767
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9526
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7927
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7084
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5952
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4567
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4168
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.