Hello,
I am searching a way to do this:
1) I have byte array or stream acting a content of file in computer memory (RAM).
2) I want to make it accessible as regular file on hard disk. The difference is that my file would be absolutely in memory.
3) That file should be discoverable by Windows Explorer. Also, it could be opened in any binary editor minimaly with read access.
I would rather prefer a managed way to do that.
Between, I would like to know if it is possible to shadow in-HDD file with my in-RAM file.
Thank you.
P.S: It should be so cheap, so it would free. :)
9 19026
So long story short, you wish to open a file and have only read access? Please elaborate.
Aimee.
Hope this will be clear:
1) File (actualy its contents) is in the memory, not in the disk! Got it? I hope so.
2) I want to make that file to seem like it was in the hard disk. But it wouldnt be there.
3) It should act like virtual file system. And all that VFS would be entirely in computer RAM.
------------------------------------------------------
Example:
User runs my app
He opens drive C: with Windows Explorer
He opens file test.txt with Notepad (And that test.txt would be provided by application)
Note:
test.txt IS NOT in the disk C:, but in RAM. R A M. Clear?
No File.Save. NO!
I just somehow need to detect when user opens a file and make it open MY stream EXISTING IN THE MEMORY!
Thanks.
Now don't get angry, but I think your missing a vital piece of a puzzle. RAM is called RAM (or random access memory) as its a place for temporary storage, where your hard disk is a permenant storage facility. Therefor the requirement you have specified dictates that you wish to have a permenant link to something that is inherantly temporary, this is why what you ask is confusing.
If we were to look at this in a different perspective, you could create your own class based memory mapping system that could include a primitive FAT (File Allocation Table). Then you could create a temporary text file that includes a pseudo path to the pseudo file you are talking about, because the class would exist in memory, effectively you would have what you were asking for.
Also if you added serialization to the class, you could add some permanence to your file system.
Thank you for better answer. (Cools down)
Could you provide some example code?
Thanks.
Im not going to write the whole thing for you, but i think its fair i atleast get you started, here is a way you could maintain your own kinda virtual filesystem. What i have done is created a new c# WinForms application, and written the following: -
public partial class Form1 : Form
-
{
-
VirtualFAT filesys = new VirtualFAT();
-
-
public Form1()
-
{
-
InitializeComponent();
-
filesys.Add(@"c:\image.png");
-
-
VirtualFile file = filesys[0];
-
MessageBox.Show(file.DateCreated.ToString());
-
MessageBox.Show(file.Data.Length.ToString());
-
}
-
}
-
-
-
public class VirtualFAT : List<VirtualFile>
-
{
-
public bool Add(string realFile)
-
{
-
bool result = false;
-
try
-
{
-
byte[] buffer = new byte[0];
-
using (FileStream fs = new FileStream(realFile, FileMode.Open, FileAccess.Read))
-
{
-
buffer = new byte[fs.Length];
-
fs.Read(buffer, 0, Convert.ToInt32(fs.Length));
-
}
-
if (buffer.Length > 0)
-
{
-
this.Add(new VirtualFile(realFile, buffer));
-
result = true;
-
}
-
}
-
catch (IOException ix) { MessageBox.Show(string.Format("Unable to add file {0}\r\n{1}", realFile,ix.Message)); }
-
catch (Exception ex) { MessageBox.Show(string.Format("{0}\r\n\r\n{1}",ex.Message,ex.StackTrace)); }
-
return result;
-
}
-
}
-
-
public class VirtualFile
-
{
-
public string Name;
-
public DateTime DateCreated;
-
public DateTime DateModified;
-
public byte[] Data;
-
public VirtualFile(string realFile, byte[] data)
-
{
-
FileInfo fi = new FileInfo(realFile);
-
Name = fi.Name;
-
DateCreated = DateTime.Now;
-
DateModified = DateTime.Now;
-
Data = data;
-
}
-
}
-
Note this is very limited, but atleast it shows you what i mean.
Aimee.
@Ernest Juska: I urge you to show the Experts some more respect. We are here as a volunteer and helping you is not mandatory. I suggest you change your attitude towards the Experts on this forum if you want an answer to your problem!
Steven
To above: I will try. :)
To the above of above:
Hi,
One thing. I don't want to load any data from disk:
MY_BYTES_IN_RAM => ???(BUT NO SAVE TO PHYSICAL DISK) => TEST.TXT => EXPLORER/NOTEPAD/HEXEDITOR/... - class Program
-
{
-
static void Main()
-
{
-
// I create data here.
-
var data = new byte[1024];
-
new Random().NextBytes(data);
-
var stream = new MemoryStream(data);
-
-
// I construct path to the file here.
-
var filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\test.txt";
-
-
// I make it accessible for Windows Explorer here.
-
// (=_=)??? how?
-
-
// Variant A:
-
// Stamp data from memory straight onto the disk.
-
// Other application would load file from disk. Not from memory. (x_x)
-
using (var file = File.Create(filePath))
-
{
-
file.Write(data, 0, data.Length);
-
}
-
-
// Variant B:
-
// Create a file server.
-
// Other application would use download file from memory. Changes could be reflected. But its slow. (o_o)
-
-
// Variant C:
-
// Create a virtual drive and associate its volume with data in memory. (O.o)???
-
// No idea how to... Maybe, somewhat to do with DeviceIOControl from kernel32.dll... And CreateFile...
-
-
// Variant D:
-
// (-_-).zZ
-
-
// I run a text editor to open the file here.
-
Process.Start("notepad", "\"" + filePath + "\"");
-
-
// I wait for exit here.
-
Console.ReadLine();
-
}
-
}
-
var data = (Stream)Make();
-
var mFile = new MemoryLinkedFile("C:\test.txt", ref data);
-
mFile.Host();
-
Console.ReadLine();
-
mFile.Quit();
-
Thanks.
There is no easy or feasible way to do this.
If you want other programs (explorer, notepad, hex editor, etc) to be able to read and see these as "files", then you will need to create something at the operating-system level. That means a driver (specifically, a storage driver)... which even experienced/expert developers find daunting.
If you want to see what the driver path is like, here's a good start http://www.microsoft.com/whdc/device...e/default.mspx.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: tony |
last post by:
hi.
how can i force a process /objects / to be always in memory and not in page
files in the hd.
is there a way to do that in programming ?
|
by: Ian Taite |
last post by:
Hello,
I'm exploring why one of my C# .NET apps has "high" memory usage, and
whether I can reduce the memory usage.
I have an app that wakes up and processes text files into a database...
|
by: Chris Putnam |
last post by:
I am working on an application that includes a feature where a
directory is spidered and thumbnails are displayed. I have it pretty
much down, but when the bitmaps are loaded from file, memory is...
|
by: noridotjabi |
last post by:
Say I'm writting a program. In this program for some reason I need to
store data somewere were I will be able to access it again. I don't
want to store it in a file because then it could be...
|
by: james.dixon |
last post by:
Hi
I have been having a bit of a look at the Microsoft Logging Application
Block (using .NET 1.1). I found it easy to get going, but now have
struck a bit of a brick wall.
I want to...
| |
by: gopal |
last post by:
Hi I have the following code for calling a Resource file
public static ResourceManager m_ResourceManager = new
ResourceManager("SMSGenerationTool.PatchGenTool",...
|
by: doanwon |
last post by:
hello, first post, thanks for reading...
Say I create an MFC Dialog program. I then click on an
"OnCreateButtons" button to create a long list of MFC buttons/objects,
which would then be...
|
by: chunk1978 |
last post by:
hi there...
i have the following codes (HTML and PHP) on my Apache Localhost:
HTML: titled "Form.html"
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input...
|
by: kamsmartx |
last post by:
hi
i have this code
but i have problem that is
i can ensert the NO of job and saved it on txt file named by memory
but when i close the file memory all data on this file is lost , how can i...
|
by: Nagu |
last post by:
I didn't have the problem with dumping as a string. When I tried to
save this object to a file, memory error pops up.
I am sorry for the mention of size for a dictionary. What I meant by...
|
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,...
| |
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,...
|
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...
|
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: 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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |