I’m using memory mapping to pull a variable from an external program. When I try to run my client in a C# project not tied to Unity, it works fine. However, when I attempt to build this functionality into a script within Unity itself, I am unable to open the file and the program does not complete. I’m very new to Unity and the concept of memory mapping, so am I missing something obvious here? Same result with both a local mapping and global.
C# Client Code
using System;
using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
using (MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("Global\\Local\\MyFileMap"))
using (MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor())
{
int takeoffStatus = accessor.ReadByte(0);
Console.WriteLine(takeoffStatus);
}
}
}
}
Unity Code
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO.MemoryMappedFiles;
using System.Runtime.InteropServices;
public class abortScript : MonoBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
using (MemoryMappedFile mmf = MemoryMappedFile.OpenExisting("Global\\Local\\MyFileMap"))
using (MemoryMappedViewAccessor accessor = mmf.CreateViewAccessor())
{
byte[] buffer = new byte[10];
for (int index = 0; index < 1; index++)
{
int takeoffStatus = accessor.ReadByte(index);
}
}
}
}
Thanks in advance