Jump to content
Tuts 4 You

patch auto saved in memory map?


PieterJones

Recommended Posts

PieterJones

hello tuts4you


 


i suppose after mapping a file in memory, and after making a change/patch in this mapped memory, i need to save the bytes wich are changed using FlushViewOfFile , right?


 


so the weird thing is, it saves the patch already without using the FlushViewOfFile api yet!


 


so actually i don't have to use FlushViewOfFile because the bytes are automatic saved after unmapping it seems.


 


can someone tell me why?



hOpenFile = CreateFile(szFilePath, GENERIC_WRITE | GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_RANDOM_ACCESS, NULL) hOpenFileMapping = CreateFileMapping(hOpenFile, NULL, PAGE_READWRITE, 0, dwSizeOfFile, NULL) pFile = MapViewOfFile(hOpenFileMapping, FILE_MAP_ALL_ACCESS, 0, 0, dwSizeOfFile) /** make a some patches in mapped file, then unmap it **/
UnmapViewOfFile(pFile);
CloseHandle(hOpenFileMapping);
CloseHandle(hOpenFile);

Edited by PieterJones
Link to comment

i suppose after mapping a file in memory, and after making a change/patch in this mapped memory, i need to save the bytes wich are changed using FlushViewOfFile , right?

Nope, you don't. Closing file handle commits all changes automagically.

FlushViewOfFile is useful in specific situations when, for example, you have the same file mapped in several processes and you want to write the changes without actually closing the handle. Something like this, for example - http://stackoverflow.com/questions/4306157/createfilemapping-synchronous-between-programs

  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...