Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8505941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T02:27:34+00:00 2026-06-11T02:27:34+00:00

I will like to use a memory mapped file to virtualize opening a file

  • 0

I will like to use a memory mapped file to virtualize opening a file on windows when that file is realy on the internet.

So I create the memory mapped file as:

// data that we write to the file. we will get this a tcp
var data = System.Text.Encoding.UTF8.GetBytes("Hello World");

var fileStream = new FileStream("SomeFile.txt", FileMode.Create);

using (MemoryMappedFile memoryMapped = MemoryMappedFile.CreateFromFile(fileStream, "MapName", 1024, 
    MemoryMappedFileAccess.ReadWrite, new MemoryMappedFileSecurity(), HandleInheritability.Inheritable, true))
{
    var viewStream = memoryMapped.CreateViewStream();                
    viewStream.Write(data, 0, data.Length); // write hello world                                
}

And I can read from it on windows but not save it:

enter image description here

Note how I was able to open the file (meanwhile the data was on memory and not the hard disk) but the moment I tried saving changes I was not able. So my question is: How could I enable saving changes to that file and be just changing the content in memory of the memory mapped file without actually trying to save anything to disk.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T02:27:35+00:00Added an answer on June 11, 2026 at 2:27 am

    You need to specify the sharing mode when creating the file stream.

    var fileStream = 
        new FileStream("SomeFile.txt", FileMode.Create, 
                       FileAccess.ReadWrite, FileShare.ReadWrite);
    

    Also, you need to dispose of your FileStream when done, e.g. with a using statement.

    UPDATE

    It worked just fine for me. Using Notepad I had to manually re-open the file, but I could update it while Notepad had it open (Notepad just did not check for external modifications).

    Side note: The code writes a bunch of NUL (0x00) bytes to the end of the file. You’ll probably want to look into that.

    Here’s the exact code I used (note the local path to C:\Temp. Change if needed):

        static private void WriteMMF()
        {
            // data that we write to the file. we will get this a tcp
            var data = System.Text.Encoding.UTF8.GetBytes("Hello World 2");
    
            using (var fileStream = new FileStream(@"C:\Temp\SomeFile.txt", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
            using (MemoryMappedFile memoryMapped = MemoryMappedFile.CreateFromFile(fileStream, "MapName", 1024,
                MemoryMappedFileAccess.ReadWrite, new MemoryMappedFileSecurity(), HandleInheritability.Inheritable, true))
            {
                var viewStream = memoryMapped.CreateViewStream();
                viewStream.Write(data, 0, data.Length); // write hello world                                
            }
        }
    
    
        static void Main(string[] args)
        {
            Console.WriteLine("Writing MMF");
    
            WriteMMF();
    
            Console.WriteLine("Done.  Press a key.");
            var ch = Console.ReadKey();
    
            return;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'd like to use use maps in my application, so that there will be
I would like to develop or use an existing platform that will allow me
I'm working on a website that will use features of social networking (like facebook
I always like to use the variable with the smallest size that will work
I will like to use the objdump command on cygwin. I get the exception:
If i use some really simple code like : $('#elm').tipTip(); It will do what
When I use make command, like make mica2, in TinyOS. The following problem will
if i use <BODY TOPMARGIN=0 LEFTMARGIN=0 MARGINHEIGHT=0 MARGINWIDTH=0> tag like this, will this ensure
I would like to use output caching with WCF Data Services and although there's
My concern is about what will use stack memory in an instruction involving arithmetics

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.