淘先锋技术网

首页 1 2 3 4 5 6 7

内存如何建立映射表?

#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

mapfile java,内存如何建立映射表