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?
I have already opened the file with appropriate modes (fmOpenReadWrite, PAGE_READWRITE), and if I overwrite the charact开发者_C百科ers, 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:
call
CreateFileMapping()
with a size that exceeds the current file size. The file will be resized to match the new mapping.use
SetFilePointer()
andSetEndOfFile()
to resize the file directly, then callCreateFileMapping()
with the new size.
Both conditions are described in the documentation for CreateFileMapping()
.
You cannot resize file mapping created with CreateFileMapping
when it's already created. See earlier discussion on the topic: Windows: Resize shared memory .
精彩评论