473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Redirecting File input to Memory

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
Feb 16 '07 #1
13 1953
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.

"RobKinney1" <Ro********@discussions.microsoft.comha scritto nel messaggio
news:43**********************************@microsof t.com...
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

Feb 16 '07 #2
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

--
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
Short urls & more: http://ittyurl.net


"RobKinney1" wrote:
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
Feb 16 '07 #3
"Laura T." wrote:
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

Feb 16 '07 #4
"Peter Bromberg [C# MVP]" wrote:
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

Feb 16 '07 #5
On Feb 16, 12:58 pm, RobKinney1 <RobKinn...@discussions.microsoft.com>
wrote:
"Laura T." wrote:
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

Feb 16 '07 #6
"rowe_newsgroups" wrote:
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
Feb 16 '07 #7
"Peter Bromberg [C# MVP]" wrote:
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
Feb 16 '07 #8
On Feb 16, 1:27 pm, RobKinney1 <RobKinn...@discussions.microsoft.com>
wrote:
"rowe_newsgroups" wrote:
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
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

Feb 16 '07 #9
"rowe_newsgroups" wrote:
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
Feb 16 '07 #10
On Fri, 16 Feb 2007 10:31:08 -0800, RobKinney1
<Ro********@discussions.microsoft.comwrote:
>"Peter Bromberg [C# MVP]" wrote:
>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
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
Feb 17 '07 #11
On Fri, 16 Feb 2007 10:31:08 -0800, RobKinney1
<Ro********@discussions.microsoft.comwrote:
>"Peter Bromberg [C# MVP]" wrote:
>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
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
Feb 17 '07 #12
Otis Mukinfus wrote in message
news:n9********************************@4ax.com...
On Fri, 16 Feb 2007 10:31:08 -0800, RobKinney1
<Ro********@discussions.microsoft.comwrote:
>>"Peter Bromberg [C# MVP]" wrote:
>>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?
Could you perhaps use a named pipe? Named pipes
are adressed like files, you know.

Regards,
Christian

Feb 17 '07 #13
"Otis Mukinfus" wrote:
I looked it up on the web here's what you want. It's $50.00

http://www.cenatek.com/product_ramdisk.cfm
Hmmm.... Interesting. So it can be done, but the solution would be fairly
complex. If only I could view their source...

Thanks.

Rob
Feb 19 '07 #14

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

Similar topics

0
by: Christophe HELFER | last post by:
hi, I have some problem with redirecting input and output from a process. I can only use VB language (sorry...) Situation: I have to use the Cisco Network Registrar (DNS And DHCP server) ...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
6
by: Christophe Helfer | last post by:
hi, I have some problem with redirecting input and output from a process. Situation: I have to use the Cisco Network Registrar (DNS And DHCP server) command line utility as redirecting its...
1
by: Gaijinco | last post by:
Hi! I was coding something which had some lines like these: int main(){ int n; scanf("%d",&n); fflush(stdin); int* ans = new int; int idx=0;
3
by: Sudesh | last post by:
Hi, I am a newbie to C# and Im trying to redirect standard input, output and error of a console program written in C (MS VC 6.0) to a textbox on a form. The code for the redirecting looks like...
8
by: Morpheus | last post by:
I am trying to test a function that outputs text to the standard output, presumably using a cout call. I do not have access to the source, but need to test the output. Is this possible? I can...
1
by: pp4175 | last post by:
Hello Everyone, I am currently working on writing a GUI wrapper for a Menu driven DOS Program. What I was looking on doing is redirecting stdout/stdin to a stream and read/write similar to a...
116
by: dmoran21 | last post by:
Hi All, I am working on a program to take input from a txt file, do some calculations, and then output the results to another txt file. The program that I've written compiles fine for me, however,...
6
by: rpcchandu | last post by:
Hi Coders, I have to redirect from my server to the different server page by simulating the POST method submit from the Controller file, I tried using post_via_redirect, but could not succeed......
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.