内存如何建立映射表?
#include <iostream>
#include <assert.h>
#include <Windows.h>
#include <WinBase.h>
#define BAD_POS 0xFFFFFFFF // returned by SetFilePointer and GetFileSize
#define SUCCESS 0
using namespace std;
typedef DWORD mmf_share_mode;
typedef DWORD mmf_access_mode;
typedef DWORD mmf_flags;
int main() {
cout << "create memorymapfile..." << endl;
const char* shared_name = "testMmf";
const char* file_name = "d:\\testMmf.mmf";
const DWORD mmf_size = 512 * 1024;
//存取模式
mmf_access_mode access_mode = (GENERIC_READ | GENERIC_WRITE);
//共享模式
mmf_share_mode share_mode = FILE_SHARE_READ | FILE_SHARE_WRITE;
//文件属性
mmf_flags flags = FILE_FLAG_SEQUENTIAL_SCAN;//|FILE_FLAG_WRITE_THROUGH|FILE_FLAG_NO_BUFFERING;
DWORD error_code;
//创建文件
HANDLE mmHandle =
CreateFile(file_name,
access_mode,
share_mode,
NULL,
OPEN_ALWAYS,
flags,
NULL);
if (mmHandle == INVALID_HANDLE_VALUE) {
error_code = GetLastError();
cout << "创建mmf失败:" << error_code << endl;
}
else {
DWORD
Copyright © 广州京杭网络科技有限公司 2005-2024 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有