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

  • SEARCH
  • Home
  • 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 7629111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:45:04+00:00 2026-05-31T05:45:04+00:00

I am working on memory mapped files. Is there any way to know the

  • 0

I am working on memory mapped files. Is there any way to know the length of memory mapped file content? What I want is to append the existing memory mapped file. Its easy to append the bytes in the file but I am looking to append string.

We can check the CAPACITY property, but it returns the bytes size I think.

To be more clear, I am explaining the scenario. I am creating Memory mapped file A. I write “Hello” when I create it. It works fine. Now I want to write the “World” into existing file A.

I am using below code for this:

 var file = MemoryMappedFile.OpenExisting("myFile");
            string str = "String to append";
            using (var view = file.CreateViewAccessor())
            {
                using (var stream = file.CreateViewStream())
                {
                    System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
                    writer.Write(str.ToArray(), INT SIZE,Convert.ToInt32(view.Capacity), str.Length);//Error
                }
            }
            using (var stream = file.CreateViewStream())
            {
                Console.WriteLine("Reading appended File");
                System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);
                Console.WriteLine(reader.ReadString());
                Console.WriteLine(string.Empty);
            }

I have marked the line with (//) that asks for the size. I want to know the value for (INT SIZE)
Any help would be appreciated.

[EDIT] I am using C#, Visual Studio 2010.

Now I am using this code to append:

var file = MemoryMappedFile.OpenExisting("myFile");
            string str = "String to append";
            string str1 = string.Empty;


            using (var stream = file.CreateViewStream())
            {
                System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);

                str1 = reader.ReadString();
                str1 = str1 + "\n" + str;

                System.IO.BinaryWriter writer = new System.IO.BinaryWriter(stream);
                writer.Write(str1);
            }
            using (var stream = file.CreateViewStream())
            {
                Console.WriteLine("Reading appended File");
                System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);
                Console.WriteLine(reader.ReadString());
                Console.WriteLine(string.Empty);
            }

But its not appending anything. Can you please check my code?

  • 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-05-31T05:45:05+00:00Added an answer on May 31, 2026 at 5:45 am

    You can’t append to a string in the stream by writing more character after it, as that won’t change the length of the string already written.

    Also, there is no method of the BinaryWriter that lets you write to a specific position in the stream like that. For the overload that takes a character array and two integers, the second parameter specifies the position in the array, not the position in the stream.

    If you want to change the string written in the stream, you have to read the string from the stream and rewrite the stream with the new string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was working on a thread safe queue backed by memory mapped files which
I'm working with large, and growing files using the managed wrappers for memory-mapped files:
I'm new to pointers/memory operations and am working on some sample programs. I want
I have a process that uses a lot of memory mapped files. Problem is
I am trying to use memory-mapped files as: hFile = ::CreateFile(State.Path, GENERIC_READ, FILE_SHARE_READ |
Is it possible to create a memory mapped file for interprocess communication with a
.Net 4 will have a brilliant support for memory mapped files. The two main
I want to prevent memory working set minimize in Console application. In windows application,
so this the code snipit: static void Main(string[] args) { Console.WriteLine(Memory mapped file reader
I'm working on a memory tracking library where we use mprotect to remove access

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.