Redirecting File input to Memory

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

Here is a head scratcher for you all: We were wondering if it is possible
to redirect file input to a place in memory (say a byte array for example).

More specifically, if a function were to take only an input string directed
to a file path (physical hard drive location), is there a way to trick that
function into reading a memory location instead that we manage? Is this
possible?

Thanks,

Rob
 
I'm not sure what you mean with "..an input string directed to a file path",
but if the functions use streams, you might try to use MemoryStream.
 
A file is nothing more than a stream of bytes on the media (hard drive).
You can store a byte array in a database table, in a Hashtable (or Generics
equivalent) and so on.
So to the extent that you could rewrite (or overload) your method
("function" as you called it) to look to a Hashtable instead of a file for
that stream of byte data, the storage mechanics would be the same.

But I don't think there is a way to "trick" an existing method to do
something different from what the code in it does.

Hope that helps.
Peter
 
Laura T. said:
I'm not sure what you mean with "..an input string directed to a file path",
but if the functions use streams, you might try to use MemoryStream.

Hello Laura Thank you for replying.

Consider the code below:

// normally this is how the code is written
// and only takes a string path... its not overloaded
// for a stream object (although I wish it was!! :~})
GenericLibraryCall.OpenFile("c:\temp\myFile.txt");

// Is there a tricky way to open from a byte array?
byte [] myMemData = { /* raw byte data here */};

GenericLibraryCall.OpenFile(/* somehow trick and redirect to byte array */);


I know this sounds odd, but the library we are using is restricted to a file
path. We need a way to redirect the input into a byte array that we are
managing.

This may not be possible.

Thanks,

Rob
 
Peter Bromberg said:
A file is nothing more than a stream of bytes on the media (hard drive).
You can store a byte array in a database table, in a Hashtable (or Generics
equivalent) and so on.
So to the extent that you could rewrite (or overload) your method
("function" as you called it) to look to a Hashtable instead of a file for
that stream of byte data, the storage mechanics would be the same.

But I don't think there is a way to "trick" an existing method to do
something different from what the code in it does.

Hope that helps.
Peter

Peter, thank you for replying. This is what I was afraid of. The method we
are referring to is a 3rd party library call, so we were trying to find a way
to get around the file path restriction.

Thank you for your help. :~} Its back to the drawing board.

Rob
 
Laura T. said:
I'm not sure what you mean with "..an input string directed to a file path",
but if the functions use streams, you might try to use MemoryStream.

Hello Laura Thank you for replying.

Consider the code below:

// normally this is how the code is written
// and only takes a string path... its not overloaded
// for a stream object (although I wish it was!! :~})
GenericLibraryCall.OpenFile("c:\temp\myFile.txt");

// Is there a tricky way to open from a byte array?
byte [] myMemData = { /* raw byte data here */};

GenericLibraryCall.OpenFile(/* somehow trick and redirect to byte array */);

I know this sounds odd, but the library we are using is restricted to a file
path. We need a way to redirect the input into a byte array that we are
managing.

This may not be possible.

Thanks,

Rob

Couldn't you use a stream to first write the bytearray into a file and
then pass that file to the function?

Thanks,

Seth Rowe
 
rowe_newsgroups said:
Couldn't you use a stream to first write the bytearray into a file and
then pass that file to the function?

Thanks,

Seth Rowe

Hello Seth, and thank you for replying. I wish we could do as you suggest,
but due to security reasons, we were told we by our boss we cannot have the
file resident on the hard drive. But I like the logicalness of your answer.

Thanks,

Rob
 
Peter Bromberg said:
A file is nothing more than a stream of bytes on the media (hard drive).
You can store a byte array in a database table, in a Hashtable (or Generics
equivalent) and so on.
So to the extent that you could rewrite (or overload) your method
("function" as you called it) to look to a Hashtable instead of a file for
that stream of byte data, the storage mechanics would be the same.

But I don't think there is a way to "trick" an existing method to do
something different from what the code in it does.

I did have a though though... Does anyone know of a way to remap a physical
location to memory by way of some kind of virtual location setup. I remember
a long time ago I used to have some kind of RAM Disk utility that expanded my
memory by using a swap file on the hard drive. I am trying to do this in
reverse. Any ideas?

Thanks,

Rob
 
Hello Seth, and thank you for replying. I wish we could do as you suggest,
but due to security reasons, we were told we by our boss we cannot have the
file resident on the hard drive. But I like the logicalness of your answer.

Thanks,

Rob

If you don't mind me asking, what the heck are you moving that it can
exist only in memory due to security?

Also how are you getting the bytearray in the first place?

Thanks,

Seth Rowe
 
rowe_newsgroups said:
If you don't mind me asking, what the heck are you moving that it can
exist only in memory due to security?

Sure. This object is a sensitive MP3 file.
Also how are you getting the bytearray in the first place?

My coworker has developed a file streaming program that transfers the file
from our server to our client app and we are using a library for playback
that only takes paths to an audio file.

To be honest, this is my last ditch effort before ordering a DirectShow
book and writing a source filter. I am trying to get around the fact that
the graphBuilder RenderFile() can only take a hard-coded string file
location. I don't particularly want to start programming in C++ again. We
are also not able to use the DirectShowLib.dll because of licensing purposes.
:~{

Rob
 
I did have a though though... Does anyone know of a way to remap a physical
location to memory by way of some kind of virtual location setup. I remember
a long time ago I used to have some kind of RAM Disk utility that expanded my
memory by using a swap file on the hard drive. I am trying to do this in
reverse. Any ideas?

Thanks,

Rob

I think you are thinking of RAMDISK. Where you create a ram disk in memory that
simulates a disk drive, but I haven't seen that done since the DOS days. If you
can still do it it would work for you, because it was completely in memory and
went away when the machine was turned off.

No fair making fun of how old I am ;o)

Good luck with your project,

Otis Mukinfus

http://www.otismukinfus.com
http://www.arltex.com
http://www.tomchilders.com
http://www.n5ge.com
 
I did have a though though... Does anyone know of a way to remap a physical
location to memory by way of some kind of virtual location setup. I remember
a long time ago I used to have some kind of RAM Disk utility that expanded my
memory by using a swap file on the hard drive. I am trying to do this in
reverse. Any ideas?

Thanks,

Rob

I looked it up on the web here's what you want. It's $50.00

http://www.cenatek.com/product_ramdisk.cfm


Good luck with your project,

Otis Mukinfus

http://www.otismukinfus.com
http://www.arltex.com
http://www.tomchilders.com
http://www.n5ge.com
 
Otis Mukinfus wrote in message

Could you perhaps use a named pipe? Named pipes
are adressed like files, you know.

Regards,
Christian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top