Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

MemoryMappedFile::CreateNew Method (String^, Int64)

.NET Framework (current version)
 

Creates a memory-mapped file that has the specified capacity in system memory.

Namespace:   System.IO.MemoryMappedFiles
Assembly:  System.Core (in System.Core.dll)

public:
static MemoryMappedFile^ CreateNew(
	String^ mapName,
	long long capacity
)

Parameters

mapName
Type: System::String^

A name to assign to the memory-mapped file.

capacity
Type: System::Int64

The maximum size, in bytes, to allocate to the memory-mapped file.

Return Value

Type: System.IO.MemoryMappedFiles::MemoryMappedFile^

A memory-mapped file that has the specified name and capacity.

Exception Condition
ArgumentException

mapName is an empty string.

ArgumentNullException

mapName is null.

ArgumentOutOfRangeException

capacity is less than or equal to zero.

Use this method to create a memory-mapped file that is not persisted (that is, not associated with a file on disk), which you can use to share data between processes.

The following example is composed of three separate processes (console applications) that write Boolean values to a memory-mapped file. The following sequence of actions occur:

  1. Process A creates the memory-mapped file and writes a value to it.

  2. Process B opens the memory-mapped file and writes a value to it.

  3. Process C opens the memory-mapped file and writes a value to it.

  4. Process A reads and displays the values from the memory-mapped file.

  5. After Process A is finished with the memory-mapped file, the file is immediately reclaimed by garbage collection.

To run this example, do the following:

  1. Compile the applications and open three Command windows.

  2. In the first Command window, run Process A.

  3. In the second Command window, run Process B.

  4. Return to Process A and press ENTER.

  5. In the third Command window, run Process C.

  6. Return to Process A and press ENTER.

The output of Process A is as follows:

Start Process B and press ENTER to continue.
Start Process C and press ENTER to continue.
Process A says: True
Process B says: False
Process C says: True

Process A

No code example is currently available or this language may not be supported.

Process B

No code example is currently available or this language may not be supported.

Process C

No code example is currently available or this language may not be supported.

.NET Framework
Available since 4.0
Return to top
Show:
© 2017 Microsoft