Type a page name and press Enter. You'll jump to the page if it exists, or you can create it if it doesn't.
To create a page in a module other than kernel32, prefix the name with the module name and a period.
/// <summary>
/// A managed version of Memory mapped file
/// By SHG at mail@Toolsbox.dk
/// </summary>
public class CMemoryMappedFile : IDisposable
{
IntPtr _hMMF = IntPtr.Zero;
FileStream _fs;
public uint _AllocationGranularity;
BinaryFormatter _Formatter = new BinaryFormatter();
/// <summary>
/// Creates a FileMapping handel
/// </summary>
/// <param name="FileName"></param>
/// <param name="Name"></param>
public CMemoryMappedFile(string FileName, string Name)
{
_fs = File.Open(FileName, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
_hMMF = Win32API.CreateFileMapping(_fs, Win32API.FileMapProtection.PageReadWrite, Int64.MaxValue, Name);
if (_hMMF == IntPtr.Zero)
throw new Win32Exception();
/// <summary>
/// Creates a FileMapping handel, file must be opened, in the OS, with CMemoryMappedFile(string FileName, string Name)
/// </summary>
/// <param name="Name"></param>
public CMemoryMappedFile(string Name)
{
_hMMF = Win32API.OpenFileMapping(Win32API.FileMapAccess.FileMapAllAccess, false, Name);
if (_hMMF == IntPtr.Zero)
throw new Win32Exception();
hMVF = Win32API.MapViewOfFile(_hMMF, Win32API.FileMapAccess.FileMapRead, FileMapStart, (Int32)MapViewSize);
if (hMVF == IntPtr.Zero)
throw new Win32Exception();
byte* p = (byte*)hMVF.ToPointer() + iViewDelta;
UnmanagedMemoryStream ums = new UnmanagedMemoryStream(p, MapViewSize, MapViewSize, FileAccess.Read);
byte[] ba = new byte[BytesToRead];
return ums.Read(Buffer, 0, BytesToRead);
}
finally
{
if (hMVF != IntPtr.Zero)
Win32API.UnmapViewOfFile(hMVF);
}
}
/// <summary>
/// returns the streamed size of an object
/// </summary>
/// <param name="T"></param>
/// <returns></returns>
public long Size(Object T)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(ms, T);
return ms.Length;
}
public void Dispose()
{
if (_hMMF != IntPtr.Zero)
Win32API.CloseHandle(_hMMF);
_hMMF = IntPtr.Zero;
if (_fs != null)
_fs.Close();
}
}
[StructLayout(LayoutKind.Sequential)]
internal struct SYSTEM_INFO
{
internal _PROCESSOR_INFO_UNION uProcessorInfo;
public uint dwPageSize;
public IntPtr lpMinimumApplicationAddress;
public IntPtr lpMaximumApplicationAddress;
public IntPtr dwActiveProcessorMask;
public uint dwNumberOfProcessors;
public uint dwProcessorType;
public uint dwAllocationGranularity;
public ushort dwProcessorLevel;
public ushort dwProcessorRevision;
}
The CreateFileMapping function creates or opens a named or unnamed file mapping object for the specified file.
12/22/2021 12:26:55 AM - 45.129.136.32
Please edit this page!
Do you have...
helpful tips or sample code to share for using this API in managed code?
corrections to the existing content?
variations of the signature you want to share?
additional languages you want to include?
Select "Edit This Page" on the right hand toolbar and edit it! Or add new pages containing supporting types needed for this API (structures, delegates, and more).