473,508 Members | 2,247 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

File in memory

5 New Member
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. :)
Aug 11 '10 #1
9 19026
Aimee Bailey
197 Recognized Expert New Member
So long story short, you wish to open a file and have only read access? Please elaborate.

Aimee.
Aug 12 '10 #2
Ernest Juska
5 New Member
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.
Aug 12 '10 #3
Aimee Bailey
197 Recognized Expert New Member
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.
Aug 12 '10 #4
Ernest Juska
5 New Member
Thank you for better answer. (Cools down)

Could you provide some example code?

Thanks.
Aug 13 '10 #5
Aimee Bailey
197 Recognized Expert New Member
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:

Expand|Select|Wrap|Line Numbers
  1.     public partial class Form1 : Form
  2.     {
  3.         VirtualFAT filesys = new VirtualFAT();
  4.  
  5.         public Form1()
  6.         {
  7.             InitializeComponent();
  8.             filesys.Add(@"c:\image.png");
  9.  
  10.             VirtualFile file = filesys[0];
  11.             MessageBox.Show(file.DateCreated.ToString());
  12.             MessageBox.Show(file.Data.Length.ToString());
  13.         }
  14.     }
  15.  
  16.  
  17.     public class VirtualFAT : List<VirtualFile>
  18.     {
  19.         public bool Add(string realFile)
  20.         {
  21.             bool result = false;
  22.             try
  23.             {
  24.                 byte[] buffer = new byte[0];
  25.                 using (FileStream fs = new FileStream(realFile, FileMode.Open, FileAccess.Read))
  26.                 {
  27.                     buffer = new byte[fs.Length];
  28.                     fs.Read(buffer, 0, Convert.ToInt32(fs.Length));
  29.                 }
  30.                 if (buffer.Length > 0)
  31.                 {
  32.                     this.Add(new VirtualFile(realFile, buffer));
  33.                     result = true;
  34.                 }
  35.             }
  36.             catch (IOException ix) { MessageBox.Show(string.Format("Unable to add file {0}\r\n{1}", realFile,ix.Message)); }
  37.             catch (Exception ex) { MessageBox.Show(string.Format("{0}\r\n\r\n{1}",ex.Message,ex.StackTrace)); }
  38.             return result;
  39.         }
  40.     }
  41.  
  42.     public class VirtualFile
  43.     {
  44.         public string Name;
  45.         public DateTime DateCreated;
  46.         public DateTime DateModified;
  47.         public byte[] Data;
  48.         public VirtualFile(string realFile, byte[] data)
  49.         {
  50.             FileInfo fi = new FileInfo(realFile);
  51.             Name = fi.Name;
  52.             DateCreated = DateTime.Now;
  53.             DateModified = DateTime.Now;
  54.             Data = data;
  55.         }
  56.     }
  57.  
Note this is very limited, but atleast it shows you what i mean.

Aimee.
Aug 13 '10 #6
MrMancunian
569 Recognized Expert Contributor
@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
Aug 13 '10 #7
Ernest Juska
5 New Member
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/...

Expand|Select|Wrap|Line Numbers
  1.     class Program
  2.     {
  3.         static void Main()
  4.         {
  5.             // I create data here.
  6.             var data = new byte[1024];
  7.             new Random().NextBytes(data);
  8.             var stream = new MemoryStream(data);
  9.  
  10.             // I construct path to the file here.
  11.             var filePath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\test.txt";
  12.  
  13.             // I make it accessible for Windows Explorer here.
  14.             // (=_=)??? how?
  15.  
  16.                 // Variant A:
  17.                 // Stamp data from memory straight onto the disk.
  18.                 // Other application would load file from disk. Not from memory. (x_x)
  19.                 using (var file = File.Create(filePath))
  20.                 {
  21.                     file.Write(data, 0, data.Length);
  22.                 }
  23.  
  24.                 // Variant B:
  25.                 // Create a file server.
  26.                 // Other application would use download file from memory. Changes could be reflected. But its slow. (o_o)
  27.  
  28.                 // Variant C:
  29.                 // Create a virtual drive and associate its volume with data in memory. (O.o)???
  30.                 // No idea how to... Maybe, somewhat to do with DeviceIOControl from kernel32.dll... And CreateFile...
  31.  
  32.                 // Variant D:
  33.                 // (-_-).zZ
  34.  
  35.             // I run a text editor to open the file here.
  36.             Process.Start("notepad", "\"" + filePath + "\"");
  37.  
  38.             // I wait for exit here.
  39.             Console.ReadLine();
  40.         }
  41.     }
Expand|Select|Wrap|Line Numbers
  1. var data = (Stream)Make();
  2. var mFile = new MemoryLinkedFile("C:\test.txt", ref data);
  3. mFile.Host();
  4. Console.ReadLine();
  5. mFile.Quit();
  6.  
Thanks.
Aug 14 '10 #8
Alex Papadimoulis
26 Recognized Expert New Member
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.
Aug 15 '10 #9
Ernest Juska
5 New Member
Found other way...

Use custom plugin for Pismo File Mount Audit Package (http://www.pismotechnic.com/download)

Thanks.

P.S: I will still look at storage drivers. Interesting.
Aug 16 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
1596
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 ?
3
4112
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...
0
2223
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...
3
3135
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...
0
2048
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...
0
1041
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",...
1
1411
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...
5
13875
chunk1978
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...
21
1792
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...
1
6250
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...
0
7229
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,...
0
7333
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
7502
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
5637
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,...
1
5057
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...
0
4716
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...
0
3194
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1566
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 ...
1
769
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.