将数据附加到MapViewOfFile中的内存映射文件 [英] append data to memory mapped file in MapViewOfFile

查看:169
本文介绍了将数据附加到MapViewOfFile中的内存映射文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在使用MapViewOfFile映射文件并尝试编辑其数据并将其保存在文件中。

我有额外的问题数据到扩展其大小所需的文件。

那么,如何使用CreateFileMapping和MapViewOfFile将数据附加到内存映射文件的末尾?

Hello guys,
I''m using MapViewOfFile to map a file and try to edit its data and save it on the file.
The problem I have extra data to the file required to expand its size.
So, how to append data to the end of memory mapped file using CreateFileMapping and MapViewOfFile?

推荐答案

尝试使用下面的方法创建大尺寸的文件映射并更新内容。

Try to use the below method it create file mapping with large size and update the contents.
DWORD nSize = GetFileSize( hFile, &nSizeH );
    int nRequiredSize = nSize + nAddedSize;// New size is calculated for file mapping.
    HANDLE hMapping = CreateFileMapping( hFile, 0, PAGE_READWRITE, 0,nRequiredSize,0 );
    CHAR* pData = (CHAR*)MapViewOfFile( hMapping, FILE_MAP_ALL_ACCESS, 0,0, 0 );
    // Append data to pData
    UnmapViewOfFile(pData);
    CloseHandle(hMapping);


这篇关于将数据附加到MapViewOfFile中的内存映射文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆