MemoryMappedFileStatic: CreateFromFileStream

CreateFromFileStream

Creates a memory-mapped file that has the specified name, capacity, access type, and disposal requirement from a file on disk.



 Public Function CreateFromFileStream(
	  ByVal FileStream As FileStream,
	  ByRef MapName As String,
	  ByVal Capacity As Currency,
	  ByVal Access As MemoryMappedFileAccess,
	  ByVal LeaveOpen As Boolean ) As MemoryMappedFile

Parameters

FileStream
[ByVal] FileStream. The FileStream to the file to map.
MapName
[ByRef] String. A name to assign to the memory-mapped file. Specify vbNullString to leave mapping unnamed.
Capacity
[ByVal] Currency. The maximum size, in bytes, to allocate to the memory-mapped file. Specify 0 to set the capacity to the size of the file on disk.
Access
[ByVal] MemoryMappedFileAccess. One of the enumeration values that specifies the type of access allowed to the memory-mapped file.

This parameter cant be set to WriteOnly.

LeaveOpen
[ByVal] Boolean. True to not dispose fileStream after the MemoryMappedFile is closed; False to dispose FileStream.

Return Values

MemoryMappedFile -  A memory-mapped file that has the specified characteristics.

Remarks

If Capacity is larger than the size of the file on disk, the file on disk is increased to match the specified capacity even if no data is written to the memory-mapped file. To prevent this from occurring, specify 0 (zero) for the default capacity, which will internally set Capacity to the size of the file on disk.

Exceptions

ExceptionCondition
ArgumentException MapName is an empty string.
-or-
Capacity and the length of the file are zero.
-or-
Access is set to the WriteOnly enumeration value, which is not allowed.
-or-
Access is set to the ReadOnly enumeration value and Capacity is larger than file size.
ArgumentNullExceptionFileStream is Nothing.
ArgumentOutOfRangeException Capacity is less than zero.
-or-
Capacity is less than the file size.
-or-
Access is not a valid MemoryMappedFileAccess enumeration value.
ObjectDisposedExceptionFileStream was closed.
IOExceptionMapName already exists.

See Also

Project CorLib Overview

Class MemoryMappedFileStatic Overview