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 8702783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:44:20+00:00 2026-06-13T02:44:20+00:00

I am following this tutorial here I am having a hard time figuring out

  • 0

I am following this tutorial here

I am having a hard time figuring out how to get a string “THIS IS A TEST MESSAGE” to store in the memory mapped file and then pull it out on the other side. The tutorial says to use byte array. Forgive me I am new to this and trying on my own first.

Thanks,
Kevin

##Write to mapped file

using System;
using System.IO.MemoryMappedFiles;

class Program1
{
    static void Main()
    {
        // create a memory-mapped file of length 1000 bytes and give it a 'map name' of 'test'
        MemoryMappedFile mmf = MemoryMappedFile.CreateNew("test", 1000);
        // write an integer value of 42 to this file at position 500
        MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor();
        accessor.Write(500, 42);
        Console.WriteLine("Memory-mapped file created!");
        Console.ReadLine(); // pause till enter key is pressed
        // dispose of the memory-mapped file object and its accessor
        accessor.Dispose();
        mmf.Dispose();
    }
}   


##read from mapped file  
using System;
using System.IO.MemoryMappedFiles;
class Program2
{
    static void Main()
    {
        // open the memory-mapped with a 'map name' of 'test'
        MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("test");
        // read the integer value at position 500
        MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor();
        int value = accessor.ReadInt32(500);
        // print it to the console
        Console.WriteLine("The answer is {0}", value);
        // dispose of the memory-mapped file object and its accessor
        accessor.Dispose();
        mmf.Dispose();
    }
}
  • 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-13T02:44:22+00:00Added an answer on June 13, 2026 at 2:44 am

    You can consider writing the length of the string and then the byte[] form of your string.
    For example if I would like to write “Hello” then I convert it into bytes:

    byte[] Buffer = ASCIIEncoding.ASCII.GetBytes("Hello");
    

    then do following while writing into the memory mapped file.

    MemoryMappedFile mmf = MemoryMappedFile.CreateNew("test", 1000);
    MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor();
    accessor.Write(54, (ushort)Buffer.Length);
    accessor.WriteArray(54 + 2, Buffer, 0, Buffer.Length);
    

    While reading first go to position 54 and read 2 bytes holding length of your string. Then you can read an array of that length and convert it into string.

    MemoryMappedFile mmf = MemoryMappedFile.CreateNew("test", 1000);
    MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor();
    ushort Size = accessor.ReadUInt16(54);
    byte[] Buffer = new byte[Size];
    accessor.ReadArray(54 + 2, Buffer, 0, Buffer.Length); 
    MessageBox.Show(ASCIIEncoding.ASCII.GetString(Buffer));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am following a CSS3 transition tutorial: here I cant manage to get this
I'm following this tutorial here http://www.kriesi.at/archives/create-a-multilevel-dropdown-menu-with-css-and-improve-it-via-jquery on adding a menu with jquery. I've created
Following Ray Wenderlich's new tutorial I was able to get JSON data and store
I'm following this tutorial attempting to learn XNA, but I'm having issues making my
I was following this tutorial, bit stuck here: This code doesn't compile, and the
I am following this tutorial to setup spring in my system, http://www.roseindia.net/spring/spring-mvc-hello-world.shtml . Here
I am following their tutorial here: http://developers.sones.de/wiki/doku.php?id=quickreference:fiveminuteguide But when I copy and paste this
Following this tutorial and running into trouble. [TestMethod] [ExpectedException(typeof(Exception))] public void VerifyPropertyNameMethod_NonExistentPropertyString_ThrowsException() { var
Following this tutorial (http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/handling-concurrency-with-the-entity-framework-in-an-asp-net-mvc-application), I learned how to save data and do concurrency checks
i'm following this tutorial: http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide and downloading my own source of mod_wsgi. The problem

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.