This topic has not yet been rated - Rate this topic

MemoryMappedViewAccessor Class

Updated: September 2010

Represents a randomly accessed view of a memory-mapped file.

System.Object
  System.IO.UnmanagedMemoryAccessor
    System.IO.MemoryMappedFiles.MemoryMappedViewAccessor

Namespace:  System.IO.MemoryMappedFiles
Assembly:  System.Core (in System.Core.dll)
public sealed class MemoryMappedViewAccessor : UnmanagedMemoryAccessor

The MemoryMappedViewAccessor type exposes the following members.

  Name Description
Public property CanRead Determines whether the accessor is readable. (Inherited from UnmanagedMemoryAccessor.)
Public property CanWrite Determines whether the accessory is writable. (Inherited from UnmanagedMemoryAccessor.)
Public property Capacity Gets the capacity of the accessor. (Inherited from UnmanagedMemoryAccessor.)
Protected property IsOpen Determines whether the accessor is currently open by a process. (Inherited from UnmanagedMemoryAccessor.)
Public property SafeMemoryMappedViewHandle Gets a handle to the view of a memory-mapped file.
Top
  Name Description
Public method Dispose() Releases all resources used by the UnmanagedMemoryAccessor. (Inherited from UnmanagedMemoryAccessor.)
Protected method Dispose(Boolean) Releases the unmanaged resources used by the UnmanagedMemoryAccessor and optionally releases the managed resources. (Inherited from UnmanagedMemoryAccessor.)
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Flush Clears all buffers for this view and causes any buffered data to be written to the underlying file.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method Initialize Sets the initial values for the accessor. (Inherited from UnmanagedMemoryAccessor.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Read<T> Reads a structure of type T from the accessor into a provided reference. (Inherited from UnmanagedMemoryAccessor.)
Public method ReadArray<T> Reads structures of type T from the accessor into an array of type T. (Inherited from UnmanagedMemoryAccessor.)
Public method ReadBoolean Reads a Boolean value from the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method ReadByte Reads a byte value from the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method ReadChar Reads a character from the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method ReadDecimal Reads a decimal value from the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method ReadDouble Reads a double-precision floating-point value from the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method ReadInt16 Reads a 16-bit integer from the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method ReadInt32 Reads a 32-bit integer from the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method ReadInt64 Reads a 64-bit integer from the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method ReadSByte Reads an 8-bit signed integer from the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method ReadSingle Reads a single-precision floating-point value from the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method ReadUInt16 Reads an unsigned 16-bit integer from the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method ReadUInt32 Reads an unsigned 32-bit integer from the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method ReadUInt64 Reads an unsigned 64-bit integer from the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method Write(Int64, Boolean) Writes a Boolean value into the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method Write(Int64, Byte) Writes a byte value into the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method Write(Int64, Char) Writes a character into the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method Write(Int64, Decimal) Writes a decimal value into the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method Write(Int64, Double) Writes a Double value into the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method Write(Int64, Int16) Writes a 16-bit integer into the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method Write(Int64, Int32) Writes a 32-bit integer into the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method Write(Int64, Int64) Writes a 64-bit integer into the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method Write(Int64, SByte) Writes an 8-bit integer into the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method Write(Int64, Single) Writes a Single into the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method Write(Int64, UInt16) Writes an unsigned 16-bit integer into the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method Write(Int64, UInt32) Writes an unsigned 32-bit integer into the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method Write(Int64, UInt64) Writes an unsigned 64-bit integer into the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method Write<T>(Int64, T) Writes a structure into the accessor. (Inherited from UnmanagedMemoryAccessor.)
Public method WriteArray<T> Writes structures from an array of type T into the accessor. (Inherited from UnmanagedMemoryAccessor.)
Top

Use the CreateViewAccessor method of a MemoryMappedFile object to get this view.

The following example obtains a MemoryMappedViewAccessor from a large memory-mapped file for editing.

This code example is part of a larger example provided for the MemoryMappedFile class.


        // 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);
				}
			}


.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Date

History

Reason

September 2010

Added example.

Information enhancement.

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ