-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Closed
Closed
Copy link
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.IOgood first issueIssue should be easy to implement, good for first-time contributorsIssue should be easy to implement, good for first-time contributorshelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributors
Milestone
Description
Background and motivation
Since .Net 7, MemoryMappedFile use SafeFileHandle instead of FileStream to create and use(see issue #63790), but the MemoryMappedFile.CreateFromFile method only accept filePath or fileStream to create.
API Proposal
using Microsoft.Win32.SafeHandles;
namespace System.IO.MemoryMappedFiles
{
public class MemoryMappedFile : IDisposable
{
public static MemoryMappedFile CreateFromFile(SafeFileHandle fileHandle, string? mapName, long capacity, MemoryMappedFileAccess access, HandleInheritability inheritability, bool leaveOpen);
}
}
API Usage
using SafeFileHandle fileHandle = File.OpenHandle("test.txt",FileAccess.ReadWrite);
int fileLength = RandomAccess.GetLength(fileHandle);
//open mmf using FileHandle
using MemoryMappedFile mmf = MemoryMappedFile.CreateFromFile(fileHandle, "mmf", fileLength, MemoryMappedFileAccess.ReadWrite, HandleInheritability.None, true);Alternative Designs
No response
Risks
This is a new extension method on MemoryMappedFile so I can't think of any risks of breaking changes.
Metadata
Metadata
Assignees
Labels
api-approvedAPI was approved in API review, it can be implementedAPI was approved in API review, it can be implementedarea-System.IOgood first issueIssue should be easy to implement, good for first-time contributorsIssue should be easy to implement, good for first-time contributorshelp wanted[up-for-grabs] Good issue for external contributors[up-for-grabs] Good issue for external contributors