0

In the olden days of DEC/HP VMS Vax Basic, there was a way to define a record's fields and "map" that definition to an open file. When a record was read, the fields defined in the map were populated for that record without coding the parsing and setting. It used to look like this:

MAP (Bec) STRING Owner = 30%, LONG Vehicle_number,    &
          STRING Serial_number = 22%
OPEN "VEH.IDN" FOR INPUT AS FILE #2%,                 &
      ORGANIZATION SEQUENTIAL FIXED,                  &
      MAP Bec, ACCESS READ
INPUT "Which record do you want";A%
WHILE (A% <> 0%)
   GET #2%, RECORD A%
   PRINT "The vehicle number is", Vehicle_number
   PRINT "The serial number is", Serial_number
   PRINT "The owner of vehicle";Vehicle_number; "is", Owner
   INPUT "Next Record";A%
NEXT
CLOSE #2%
END

I cannot find if there is anything similar in a .Net environment, specifically C#.

Allen
  • 33
  • 5

1 Answers1

0

In .Net Framework there is a MemoryMappedFile class, see

https://learn.microsoft.com/en-us/dotnet/api/system.io.memorymappedfiles.memorymappedfile

You could use that to create a memory mapped file, and there are methods to read and write structs to the memory area.

See the example in the link:

    long offset = 0x10000000; // 256 megabytes
    long length = 0x20000000; // 512 megabytes

    // Create the memory-mapped file.
    using (var mmf = MemoryMappedFile.CreateFromFile(@"c:\ExtremelyLargeImage.data", FileMode.Open,"ImgA"))
    {
        // Create a random access view, from the 256th megabyte (the offset)
        // to the 768th megabyte (the offset plus length).
        using (var accessor = mmf.CreateViewAccessor(offset, length))
        {
            int colorSize = Marshal.SizeOf(typeof(MyColor));
            MyColor color;

            // Make changes to the view.
            for (long i = 0; i < length; i += colorSize)
            {
                accessor.Read(i, out color);
                color.Brighten(10);
                accessor.Write(i, ref color);
            }
        }
    }
kristianp
  • 5,496
  • 37
  • 56
  • Thanks for the assist. It used to be so easy in other environments, but .Net seems to be making it really hard. – Allen Sep 18 '18 at 00:01