Skip to content

Commit 1529d1a

Browse files
Init MemoryMappedFile module (#1)
## Description <!-- Add your description here --> ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas
1 parent c0f9985 commit 1529d1a

35 files changed

+476
-573
lines changed

examples/General.ps1

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
<#
2-
.SYNOPSIS
3-
This is a general example of how to use the module.
4-
#>
1+
#
2+
# Monitor process
3+
#
4+
Show-MemoryMappedFile -Name 'shared'
55

6-
# Import the module
7-
Import-Module -Name 'PSModule'
86

9-
# Define the path to the font file
10-
$FontFilePath = 'C:\Fonts\CodeNewRoman\CodeNewRomanNerdFontPropo-Regular.tff'
11-
12-
# Install the font
13-
Install-Font -Path $FontFilePath -Verbose
14-
15-
# List installed fonts
16-
Get-Font -Name 'CodeNewRomanNerdFontPropo-Regular'
17-
18-
# Uninstall the font
19-
Get-Font -Name 'CodeNewRomanNerdFontPropo-Regular' | Uninstall-Font -Verbose
7+
#
8+
# Client that writes to the memory-mapped file
9+
#
10+
$params = @{
11+
Name = 'shared'
12+
Path = "$HOME\shared.json"
13+
Content = [PSCustomObject]@{
14+
Name = 'This is my name'
15+
Size = 'XL'
16+
Content = 'This is my content'
17+
Date = (Get-Date).ToString('yyyy-MM-dd HH:mm:ss')
18+
Tags = @('tag1', 'tag2', 'tag3')
19+
} | ConvertTo-Json -Depth 10
20+
}
21+
Set-MemoryMappedFileContent @params -PassThru

src/README.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/assemblies/LsonLib.dll

-42.5 KB
Binary file not shown.

src/classes/private/SecretWriter.ps1

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/classes/public/Book.ps1

Lines changed: 0 additions & 147 deletions
This file was deleted.

src/data/Config.psd1

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/data/Settings.psd1

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/finally.ps1

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/formats/CultureInfo.Format.ps1xml

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/formats/Mygciview.Format.ps1xml

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
function Close-MemoryMappedFile {
2+
<#
3+
.SYNOPSIS
4+
Closes and disposes an existing memory-mapped file by name.
5+
6+
.DESCRIPTION
7+
This function attempts to open an existing memory-mapped file with the specified name.
8+
If the file exists, it disposes of the file and frees the associated memory resources.
9+
If the file does not exist or has already been closed, a warning is displayed instead.
10+
This operation is useful for cleaning up unmanaged resources created with memory-mapped files.
11+
12+
.EXAMPLE
13+
Close-MemoryMappedFile -Name 'MySharedMemory'
14+
15+
Output:
16+
```powershell
17+
VERBOSE: Memory-mapped file 'MySharedMemory' closed successfully.
18+
```
19+
20+
Closes the memory-mapped file named 'MySharedMemory' and disposes of its resources.
21+
22+
.LINK
23+
https://psmodule.io/MemoryMappedFile/Functions/Close-MemoryMappedFile
24+
#>
25+
26+
[CmdletBinding()]
27+
param(
28+
# The name of the memory-mapped file to close and dispose.
29+
[Parameter(Mandatory)]
30+
[string] $Name
31+
)
32+
33+
try {
34+
$item = [System.IO.MemoryMappedFiles.MemoryMappedFile]::OpenExisting($Name)
35+
} catch {
36+
return $null
37+
}
38+
39+
if ($item) {
40+
$item.Dispose()
41+
Write-Verbose "Memory-mapped file '$Name' closed successfully."
42+
}
43+
}
44+
45+
#SkipTest:FunctionTest:Will add a test for this function in a future PR

0 commit comments

Comments
 (0)