MemoryMappedFileStatic: CreateFromFile

CreateFromFile

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



 Public Function CreateFromFile(
	  ByRef Path As String,
	  Optional ByVal Mode As FileMode = FileMode. OpenExisting,
	  Optional ByRef MapName As String,
	  Optional ByVal Capacity As Currency,
	  Optional ByVal Access As MemoryMappedFileAccess = MemoryMappedFileAccess. ReadWrite ) As MemoryMappedFile

Parameters

Path
[ByRef] String. The path to the file to map.
Mode
[ByVal] Optional. FileMode. Access mode; can be any of the FileMode enumeration values except Append.  

Default: FileMode . OpenExisting

MapName
[ByRef] Optional. String. A name to assign to the memory-mapped file. Specify vbNullString to rename unnamed.
Capacity
[ByVal] Optional. 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] Optional. MemoryMappedFileAccess. One of the enumeration values that specifies the type of access allowed to the memory-mapped file.  

Default: MemoryMappedFileAccess . ReadWrite

Return Values

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

Remarks

The Mode parameter pertains to the source file on disk.

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-
Access is not an allowed value.
-or-
Path specifies an empty file.
-or-
Access is specified as ReadOnly and Capacity is greater than the size of the file indicated by Path.
-or-
Mode is Append.
ArgumentOutOfRangeException Capacity is less than zero.
-or-
Capacity is less than the file size (but not zero).
-or-
Capacity is zero, and the size of the file on disk is also zero.
-or-
Access is not a defined MemoryMappedFileAccess value.
-or-
The size of the file indicated by Path is greater than Capacity.

See Also

Project CorLib Overview

Class MemoryMappedFileStatic Overview