By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,465 Members | 1,463 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,465 IT Pros & Developers. It's quick & easy.

creating a ram drive in csharp

P: n/a
At the moment i am implementing a ghostscript application in c#.

The Dll functions that i can import via dllimport all write to disk
directly.
As i want base64 encode the files, i don't want the slow disk access,
but do all functions in memory.

Could someone tell me if there is a way in which i can create a ram
drive, which i can write to ??

At the moment i am gooling my butt off but can't find anything

TIA

Otto

Jan 25 '07 #1
Share this Question
Share on Google+
13 Replies


P: n/a
kr********@gmail.com wrote:
Could someone tell me if there is a way in which i can create a ram
drive, which i can write to ??
How about using memory-mapped files instead?

Ebbe
Jan 25 '07 #2

P: n/a
Hello ebbe

I use the following dll import from gsdll32.dll

[DllImport("gsdll32.dll", EntryPoint="gsapi_init_with_args")]
private static extern int gsapi_init_with_args (IntPtr instance, int
argc, IntPtr argv);

As you can see the dll uses a argcounter and argvalues. The values are
filled with the following values:

args[0]="-dNOPAUSE";
args[1]="-dBATCH";
args[2]="-dSAFER";
args[3]="-sDEVICE=pdfwrite";
args[4]="-sOutputFile="+outputFile;
args[5]=inputFile;

both inputfile and outputfile contain a path or unc. there is no
functionality for using any stream type's.
can the memory mapped files be reached by a path.

or are memory mapped files just kind of pointer that i have to pass
from one application to another ???

On 25 jan, 11:28, "Ebbe Kristensen" <e...@ekologic.dkwrote:
krach.a...@gmail.com wrote:
Could someone tell me if there is a way in which i can create a ram
drive, which i can write to ??How about using memory-mapped files instead?

Ebbe
Jan 25 '07 #3

P: n/a
On 25 Jan 2007 02:14:46 -0800, kr********@gmail.com wrote:
>At the moment i am implementing a ghostscript application in c#.

The Dll functions that i can import via dllimport all write to disk
directly.
As i want base64 encode the files, i don't want the slow disk access,
but do all functions in memory.

Could someone tell me if there is a way in which i can create a ram
drive, which i can write to ??

At the moment i am gooling my butt off but can't find anything

TIA

Otto
Do the DLL functions write to a file, or to a file stream? If to a
file stream then you might get the effect that you want by using a
memory stream.

DLL -memoryStream -Base64 -disk

rossum
Jan 25 '07 #4

P: n/a
kr********@gmail.com wrote:
or are memory mapped files just kind of pointer that i have to pass
from one application to another ???
Memory mapped files are loaded into memory but otherwise behave as ordinary
files. Thus you get the speed advantage of having the file in memory without
bothering the OS - and the interface is exactly the same as if you accessed
the file on disk. You may find some more info here:

http://www.catch22.net/tuts/bigmem01.asp

Ebbe
Jan 25 '07 #5

P: n/a
<kr********@gmail.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
Hello ebbe

I use the following dll import from gsdll32.dll

[DllImport("gsdll32.dll", EntryPoint="gsapi_init_with_args")]
private static extern int gsapi_init_with_args (IntPtr instance, int
argc, IntPtr argv);

As you can see the dll uses a argcounter and argvalues. The values are
filled with the following values:

args[0]="-dNOPAUSE";
args[1]="-dBATCH";
args[2]="-dSAFER";
args[3]="-sDEVICE=pdfwrite";
args[4]="-sOutputFile="+outputFile;
args[5]=inputFile;

both inputfile and outputfile contain a path or unc. there is no
functionality for using any stream type's.
can the memory mapped files be reached by a path.
No, they can't.
But this aside why do you want to re-invent the wheel and implement a RAM disk in C#, there
are plenty of RAM disk implementations available in the public domain.

Willy.

Jan 25 '07 #6

P: n/a
Okey, here is a complete drill-down of my scenario :
- Enviroment is a windows 2003 server wunning a windows service.
- Due to company policy i am unable to install any software on the
server.
- I'm looking for a "Microsoft" solution without the use of third party
tools. Again because of company rules.

My windows service works as follows :
- it listens to a websphere MessageQueue from wich it receives a soap
message
- the soap contains base64 Postscript data
- file has to beconverted (this is my tricky part)
- file has to be re-encoded as a base64 string, and sent back as a soap
message

Due to requirements of the conversion only 1 package will do namely
ghostscript (which is currently going through a package acceptation by
the company ict managment)
ghostscript accepts only file paths as parameters. all disk io is done
by the dll that is called.
I want to avoid disk usage as much as possible to gain in speed.
hopefully this gives a better view of my problem (so not only technical
but also policy is in my way).

Jan 25 '07 #7

P: n/a
<kr********@gmail.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
Okey, here is a complete drill-down of my scenario :
- Enviroment is a windows 2003 server wunning a windows service.
- Due to company policy i am unable to install any software on the
server.
- I'm looking for a "Microsoft" solution without the use of third party
tools. Again because of company rules.
A RAM disk consist of a device driver. So, your only option (due to policy) is to develop
such a driver yourself using the WDK (Windows Driver Kit). Wonder whether the company rules
will allow you to install such device driver though.
Not also the only sofisticated drivers will outperform the OS cache manager, most RAM disk
drivers available perform worse than a modern Hard Disk subsystem.

My windows service works as follows :
- it listens to a websphere MessageQueue from wich it receives a soap
message
- the soap contains base64 Postscript data
- file has to beconverted (this is my tricky part)
- file has to be re-encoded as a base64 string, and sent back as a soap
message

Due to requirements of the conversion only 1 package will do namely
ghostscript (which is currently going through a package acceptation by
the company ict managment)
ghostscript accepts only file paths as parameters. all disk io is done
by the dll that is called.
I want to avoid disk usage as much as possible to gain in speed.
I'm not sure whether you will gain anything when using a RAM disk, as said above modern disk
subsystems are quite performant. Anyway, the only way to find out wheter a RAM disk would be
of any help is *measure*, however, as your environment is constrained by company policies, I
don't see how you will be able to accomplish this.
Note also that I doubt you will gain anything at all using A RAM disk, after all, the
slowest link is the network (10-100? times slower than a disk).
Willy.
Jan 25 '07 #8

P: n/a
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:uX**************@TK2MSFTNGP03.phx.gbl...
<kr********@gmail.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
>Okey, here is a complete drill-down of my scenario :
- Enviroment is a windows 2003 server wunning a windows service.
- Due to company policy i am unable to install any software on the
server.
- I'm looking for a "Microsoft" solution without the use of third party
tools. Again because of company rules.

A RAM disk consist of a device driver. So, your only option (due to policy) is to develop
such a driver yourself using the WDK (Windows Driver Kit). Wonder whether the company
rules will allow you to install such device driver though.
Not also the only sofisticated drivers will outperform the OS cache manager, most RAM disk
Sorry above should read:
Note, that only sophisticated ...

Willy.

Jan 25 '07 #9

P: n/a
Thnx for the response willy,

I think i'm just sticking to writing to disk and doing some performance
test there.
Tomorrow i'm doing a stress test and will await the results of that.
If disk performance is low due to huge file size's, i will then fall
back to another scenario.

Maybe an infrastructure solution raid / cache / clustering will provide
the required QOS i want.

I would like to thank everyone in the thread for their comment's.

If i ever find a good solution i will post it here again.

Jan 25 '07 #10

P: n/a
<kr********@gmail.comwrote in message
news:11*********************@v33g2000cwv.googlegro ups.com...
Thnx for the response willy,

I think i'm just sticking to writing to disk and doing some performance
test there.
Tomorrow i'm doing a stress test and will await the results of that.
If disk performance is low due to huge file size's, i will then fall
back to another scenario.
Don't know what you call huge files, but beware that your RAM disk must be at least the size
of your largest file, and this RAM space can't be used for anything else in the system,
there are far better way's to use your available RAM, really.

Maybe an infrastructure solution raid / cache / clustering will provide
the required QOS i want.
I'm don't think that Ghostscript would be able to saturate a single modern disk subsystem.
Anyway, a raid0 configuration with a couple of SATA2 drives will easily outperform a RAM
disk,

Willy.
Jan 25 '07 #11

P: n/a
Jay
"most RAM disk drivers available perform worse than a modern Hard Disk subsystem"

Is that true for mutliple random access to a large file? I would have thought that the seek time of
a hard disk subsystem would seriously slow things down if the file size is considerably larger than
the hard disk cache size. By using a RAM disk, the seek time should be much faster.

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:uX**************@TK2MSFTNGP03.phx.gbl...
<kr********@gmail.comwrote in message
news:11**********************@v33g2000cwv.googlegr oups.com...
Okey, here is a complete drill-down of my scenario :
- Enviroment is a windows 2003 server wunning a windows service.
- Due to company policy i am unable to install any software on the
server.
- I'm looking for a "Microsoft" solution without the use of third party
tools. Again because of company rules.
A RAM disk consist of a device driver. So, your only option (due to policy) is to develop
such a driver yourself using the WDK (Windows Driver Kit). Wonder whether the company rules
will allow you to install such device driver though.
Not also the only sofisticated drivers will outperform the OS cache manager, most RAM disk
drivers available perform worse than a modern Hard Disk subsystem.

My windows service works as follows :
- it listens to a websphere MessageQueue from wich it receives a soap
message
- the soap contains base64 Postscript data
- file has to beconverted (this is my tricky part)
- file has to be re-encoded as a base64 string, and sent back as a soap
message

Due to requirements of the conversion only 1 package will do namely
ghostscript (which is currently going through a package acceptation by
the company ict managment)
ghostscript accepts only file paths as parameters. all disk io is done
by the dll that is called.
I want to avoid disk usage as much as possible to gain in speed.
I'm not sure whether you will gain anything when using a RAM disk, as said above modern disk
subsystems are quite performant. Anyway, the only way to find out wheter a RAM disk would be
of any help is *measure*, however, as your environment is constrained by company policies, I
don't see how you will be able to accomplish this.
Note also that I doubt you will gain anything at all using A RAM disk, after all, the
slowest link is the network (10-100? times slower than a disk).
Willy.

Jan 26 '07 #12

P: n/a
"Jay" <nospamwrote in message news:OP*************@TK2MSFTNGP06.phx.gbl...
"most RAM disk drivers available perform worse than a modern Hard Disk subsystem"

Is that true for mutliple random access to a large file? I would have thought that the
seek time of
a hard disk subsystem would seriously slow things down if the file size is considerably
larger than
the hard disk cache size. By using a RAM disk, the seek time should be much faster.
True, but the OP is not talking about a desktop but about a server system, modern HD
subsystems (with entry level RAID controllers) with 256MB and more read/write cache are
common. Also on this kind of servers you can't afford to waste say +500MB of precious RAM
for a RAM drive, note that this memory is taken from systems memory normally used as FS
cache, so here you start competing with the systems IO subsystem, probably reducing the
overall system performnce.

Willy.

Jan 26 '07 #13

P: n/a
Jay
Good points Willy, thanks for your comments.
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
"Jay" <nospamwrote in message news:OP*************@TK2MSFTNGP06.phx.gbl...
"most RAM disk drivers available perform worse than a modern Hard Disk subsystem"

Is that true for mutliple random access to a large file? I would have thought that the
seek time of
a hard disk subsystem would seriously slow things down if the file size is considerably
larger than
the hard disk cache size. By using a RAM disk, the seek time should be much faster.
True, but the OP is not talking about a desktop but about a server system, modern HD
subsystems (with entry level RAID controllers) with 256MB and more read/write cache are
common. Also on this kind of servers you can't afford to waste say +500MB of precious RAM
for a RAM drive, note that this memory is taken from systems memory normally used as FS
cache, so here you start competing with the systems IO subsystem, probably reducing the
overall system performnce.

Willy.
Jan 26 '07 #14

This discussion thread is closed

Replies have been disabled for this discussion.