Skip to content

New-MemoryMappedFile

SYNOPSIS

Creates a memory-mapped file from a specified file path and name.

SYNTAX

__AllParameterSets

New-MemoryMappedFile [-Name] <string> [-Path] <string> [[-Size] <long>] [<CommonParameters>]

ALIASES

This cmdlet has the following aliases, {{Insert list of aliases}}

DESCRIPTION

This function creates a memory-mapped file using a specified name and backing file path. If the file exists, it uses the existing file and its size. If the file does not exist, a new file is created at the specified path. The memory-mapped file is created with a default size of 1MB unless otherwise specified. The function returns a [System.IO.MemoryMappedFiles.MemoryMappedFile] object.

EXAMPLES

EXAMPLE 1

New-MemoryMappedFile -Name 'SharedMap' -Path 'C:\Temp\shared.dat'

Output:

Capacity            : 1048576
SafeMemoryMappedFileHandle : Microsoft.Win32.SafeHandles.SafeMemoryMappedFileHandle

Creates a memory-mapped file named 'SharedMap' backed by 'C:\Temp\shared.dat' with a default size of 1MB.

PARAMETERS

-Name

The unique name for the memory-mapped file.

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: 0
  IsRequired: true
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Path

Specifies the path to the file backing the memory-mapped file.

Type: System.String
DefaultValue: ''
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: 1
  IsRequired: true
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

-Size

Specifies the size of the memory-mapped file in bytes. Defaults to 1MB.

Type: System.Int64
DefaultValue: 1048576
SupportsWildcards: false
Aliases: []
ParameterSets:
- Name: (All)
  Position: 2
  IsRequired: false
  ValueFromPipeline: false
  ValueFromPipelineByPropertyName: false
  ValueFromRemainingArguments: false
DontShow: false
AcceptedValues: []
HelpMessage: ''

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

INPUTS

OUTPUTS

System.IO.MemoryMappedFiles.MemoryMappedFile

{{ Fill in the Description }}

NOTES

Represents the memory-mapped file created using the specified parameters. The returned object can be used for inter-process communication or efficient file access.