473,855 Members | 1,986 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
In article <44***********@ mindspring.com> ,
pete <pf*****@mindsp ring.comwrote:
....
>Truthfully, some of the syntax and instructions in Simon's example are
new to me. I am already learning just from having read through it!

I thought that Simon was being sarcastic
Gee. ya think?
>and providing an example of noportable code
I think the point is that Simon's code was entirely portable.
And, like most entirely portable code, utterly useless.
>for the purpose of illustrating that this was
a system specific problem and not a C problem.
Aug 28 '06 #11
In article <44************ **********@free .teranews.com>,
Simon Biber <te******@ralmi n.ccwrote:
>Tom wrote:
>On Mon, 28 Aug 2006 20:30:31 +1000, Simon Biber <te******@ralmi n.cc>
wrote:
[...]
>> system("mkdir -p /mnt/ramdisk");
system("/sbin/mke2fs -q /dev/ram");
system("mount /dev/ram /mnt/ramdisk");
system("df /mnt/ramdisk tmp.txt");

While I was writing a reply to the first two responses ... Simon
posted what appears to be a total solution!!

If you had actually read and understood my code, you'd see that it is a
bit of a joke.
The thing about sarcasm is that it only works on a defenseless opponent.
Or, TPIAW, it fizzles when it is met in kind.
>Unfortunatel y I don't believe a similar solution is possible on Windows.
You need to actually write a driver or use someone's existing ramdisk
driver. That's rather difficult, and of course, very system specific.
Actually, there's no difference. The thing you are missing is that the
RAM disk driver is built-in in (more or less recent versions of) Linux.
So, all you are doing is invoking the user-land functions that control
the kernel driver (*).

Just as it is in DOS/Windows as long as the appropriated DEVICE=
line exists in CONFIG.SYS (or whatever the current equivalent is).

(*) Note that there exist similar drivers in DOS/Windows - where a
user-land utility controls the kernel driver.
Aug 28 '06 #12
In article <44************ ***********@dre ader32.news.xs4 all.nl>,
Ico <us****@zevv.nl wrote:
>Tom <Th********@ear thlink.netwrote :
>On Mon, 28 Aug 2006 20:30:31 +1000, Simon Biber <te******@ralmi n.cc>
wrote:
>>>Tom wrote:
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.

[ snip code ]

Holy smokes!!!
>>
While I was writing a reply to the first two responses ... Simon
posted what appears to be a total solution!!

I am groggy from lack of sleep and must rest before I test it ... but
I absolutely must acknowledge Simon's help.

Thank you, Thank you, Thank you !!!

I guess somebody here is oblivious of sarcasm.
Yes. You.

Aug 28 '06 #13
Tom wrote:
On Mon, 28 Aug 2006 05:10:48 GMT, Tom <Th********@ear thlink.net>
wrote:
>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.

Yikes! -- I just realized how specific and problematic something I use
to do back in 1986 has become! Anybody remember the $1986 AT&T model
6300 sold in the year 1986? With that dual floppy 8 k byte ram green
monochrome monitor system I used a ram disk to speed things up. Floppy
drive reads were very slow.
It's no more difficult and no less system specific than it was back
then. The difference is that if you are doing it to speed things up you
are quite possibly wasting your time and effort. Ever head of caching?
It's something some OSs are quite good at.
From the comments received I have gleaned
at least a few things.

1) The route I was hoping to take may not be the best choice.
True. If the user wants your data files on a RAM disk they can create
one and put them there. Such as on Linux making /tmp a ram disk.
2) The task is VERY sensitive to the operating system.
Yes.
3) Some folks in here absolutely hate usage of the ++ tag onto there
favorite language C.
Not necessarily. It is just that C++ is a very different language with
its own new group. So C++ is no more or less topical here than Fortran,
ML, TMS320C25 assembler or any of the other languages other than C that
I have used.
Additionally they have little patience with
anyone who has diminutive skills compared to themselves. I certainly
No, people have a lot of patience with those who have little knowledge
or skill. We have recently had some threads where people with little
knowledge or skill but who wanted to learn and were asking topical (if
simple) questions where the posts were not merely answered but the
original posters complimented. The difference is they were asking C
questions.
apologized, if needed, for using the ++ and I really am trying to
become less stupid.

Even though it would be ideal for there to be an established news
group of experts for my particular challenge ... I will again wish for
some additional advice here in this group.
Complaining at us is not the best method I've ever seen of getting advice.
After all ... my program
(that I have worked years on) is about 96% C and 4% ++. Additionally,
the ++ groups seem to be even faster in slamming up barriers and
crying out that you are in the wrong place! But again, what I hope to
do is within a C program and not something done purely at the
operating system level.
C knows nothing of disks, file systems, space, caching, ram disks or
lots of other stuff. It does know about streams, but which the file name
means is entirely up to the system and nothing to do with C.
Perhaps it is too cumbersome to create the
actual ram disk in C?
You can't in C and you never have been able to. You may be able to do it
with OS specific extensions but that discussion belongs in an OS
specific group.
But that still leaves my need to determine the
free space within the C code and provide logic that
manages the ram drive appropriately.
You can't with standard C. You will have to ask how to do that in a
group dedicated to your system.

<snip>
working. I have no information on how many times blocks of data are
being read from the hard drive. I do know the program is slow. It can
take 60 hours to process 7 years of data while moving the edge of the
window every 3 months.
Then profile it. Until you have *measured* and *know* what the bottle
neck is there is no point in doing anything.
In the past I tried using very large storage arrays. My system has
sufficient memory ... but once I set the array size above
approximately 600,000 the program will not compile. This is
troublesome because Microsoft's help reference indicates that arrays
can be of size_t which provides a limit of 0x7CFFFFFF (or
2,097,151,999 -- if I correctly converted).
Since size_t is not a number I'm and SIZE_MAX is unlikely to be
0x7CFFFFFF I suspect you have misread it. Ask in a Windows news group
since all we know is it is allowing arrays a lot larger than the
standard says it has to.
Most likely there are better ways to solve the problem than using a
Ram disk, but I am clueless to what they may be. I am certainly open
to all suggestions!!
<snip>

Then I *seriously* suggest you profile it. It is possible that even
Windows can manage caching well enough these days and that your problem
is something different.
--
Flash Gordon
Being helpful despite the attitude shown at the start of Tom's post not
because of it.
Aug 28 '06 #14
Ico
Kenny McCormack <ga*****@xmissi on.xmission.com wrote:
In article <44************ ***********@dre ader32.news.xs4 all.nl>,
Ico <us****@zevv.nl wrote:
>>Tom <Th********@ear thlink.netwrote :
>>On Mon, 28 Aug 2006 20:30:31 +1000, Simon Biber <te******@ralmi n.cc>
wrote:

Tom wrote:
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.

[ snip code ]

Holy smokes!!!
>>>
While I was writing a reply to the first two responses ... Simon
posted what appears to be a total solution!!

I am groggy from lack of sleep and must rest before I test it ... but
I absolutely must acknowledge Simon's help.

Thank you, Thank you, Thank you !!!

I guess somebody here is oblivious of sarcasm.

Yes. You.
Re-reading the previous posts I must admit you are right. I guess for me
being a nerd with few social skills it is easier to recognize sarcasm in
code then in normal language. Scary.

--
:wq
^X^Cy^K^X^C^C^C ^C
Aug 28 '06 #15
Kenny McCormack wrote:
In article <44***********@ mindspring.com> ,
pete <pf*****@mindsp ring.comwrote:
...
>>Truthfully, some of the syntax and instructions in Simon's example are
new to me. I am already learning just from having read through it!
I thought that Simon was being sarcastic

Gee. ya think?
Call it sarcasm, or a joke, or perhaps just taking things too literally.

I'm still not sure whether Tom's reply was being sarcastic in return or
if he was really thanking me without realising that the code was useless
to him.
>and providing an example of noportable code

I think the point is that Simon's code was entirely portable.
And, like most entirely portable code, utterly useless.
Well, if you're running it on a Linux system, it's not utterly useless.
It does achieve what it set out to do. The error handling could be
greatly improved, and there are certainly better ways to get the free
space on a file system than trying to parse the output of 'df'.

By the way: my program reported a value as bytes that is actually the
number of kilobytes free. If you want bytes, add a --block-size=1 option
to the df call.

--
Simon.
Aug 28 '06 #16
Simon Biber wrote:
Tom wrote:
>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.

system("mkdir -p /mnt/ramdisk");
system("/sbin/mke2fs -q /dev/ram");
system("mount /dev/ram /mnt/ramdisk");
system("df /mnt/ramdisk tmp.txt");
I'm going to feel like a total asshole if this was actually what the OP
had in mind.
Aug 28 '06 #17
Flash Gordon wrote:
It's no more difficult and no less system specific than it was back
then. The difference is that if you are doing it to speed things up you
are quite possibly wasting your time and effort. Ever head of caching?
It's something some OSs are quite good at.
It still makes sense on diskless clients that boot over NFS and so on.
It's also indicated in some applications where security is sensitive, or
for devices that need to operate in environments where moving parts are
impractical.

Aug 28 '06 #18
xenonysf wrote:
ok guys;
Please don't top-post. Your reply belongs following or interspersed
with properly trimmed quotes.

Brian
Aug 28 '06 #19
jmcgill wrote:
Flash Gordon wrote:
>It's no more difficult and no less system specific than it was back
then. The difference is that if you are doing it to speed things up you
are quite possibly wasting your time and effort. Ever head of caching?
It's something some OSs are quite good at.

It still makes sense on diskless clients that boot over NFS and so on.
It's also indicated in some applications where security is sensitive, or
for devices that need to operate in environments where moving parts are
impractical.
I agree there are good reasons for it sometimes. I just don't believe
that they necessarily apply to the OP. The maxim of measure first, on
the other hand, definitely does apply.
--
Flash Gordon
Aug 28 '06 #20

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
11044
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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
5754
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4168
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3194
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.