如何延长内存映射文件的长度? [英] How can I extend the length of a memory-mapped file?

查看:47
本文介绍了如何延长内存映射文件的长度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Delphi 7中,我使用CreateFileMapping打开一个文件,然后使用MapViewOfFile获取一个指针.

In Delphi 7, I open a file with CreateFileMapping then get a pointer by using MapViewOfFile.

如何扩展内存并在内存中添加一些字符并将其保存到该文件中?

How can I expand the memory and add some characters to the memory and have it saved to that file?

我已经使用适当的模式(fmOpenReadWrite,PAGE_READWRITE)打开了文件,如果我覆盖了字符,它将被保存到文件中,但是我需要在文件中间添加额外的值.

I have already opened the file with appropriate modes (fmOpenReadWrite, PAGE_READWRITE), and if I overwrite the characters, it gets saved to the file, but I need to add extra values in the middle of the file.

推荐答案

如果文件映射由实际文件而不是内存块支持,则可以通过以下两种方法之一调整文件大小:

If the file mapping is backed by an actual file and not a block of memory, then you can resize the file in one of two ways:

  1. 调用 CreateFileMapping(),其大小超过当前文件的大小.该文件将被调整大小以匹配新的映射.

  1. call CreateFileMapping() with a size that exceeds the current file size. The file will be resized to match the new mapping.

使用 SetFilePointer() SetEndOfFile()直接调整文件大小,然后以新大小调用 CreateFileMapping()

use SetFilePointer() and SetEndOfFile() to resize the file directly, then call CreateFileMapping() with the new size.

这两个条件在 CreateFileMapping()的文档中都有介绍.

Both conditions are described in the documentation for CreateFileMapping().

这篇关于如何延长内存映射文件的长度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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