Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Query on copying the files using memory mapped mechanism

Status
Not open for further replies.

isaisa

Programmer
May 14, 2002
97
IN
Hi,
i need some help in implementing the memory mapped file on the same machine. My aim is to copy one file from the machine drive to another file [which is to be created before copying] on the drive of the same machine using memory mapped files.

The steps are as follows:-
1. I have created the memory mapped file object associated with some file on the disk say "D:\\Source.txt". The whole of the file is mapped here. The call for creating the mapping object was successful. This memory mapped object is a named object.
2. Then i tried using MapViewOfFile() for some file operations. These operations were also successful.
3. Now i want to copy the contents of the file "D:\\Source.txt" to the new file "D:\\Destination.txt" on the same drive using the memory mapped object [Use of existing memory mapped object]. The new file is to be created before copying the contents.

Note: I am trying to do this with the help of memory mapped files only.

Can anybody suggest
Code:
 on this?


Thanks in advance
Sanjay
 
See Microsoft: Visual C++ forum.
isaisa
Query in file copying using memory mapped files.


HyperEngineer
If it ain't broke, it probably needs improvement.
 
Memory mapped files on Windows are not the same as those on Unix. They are only committed when you release them. Each process that wants to access the files has to lock them, do whatever reads/writes and then release them. Once a process has a lock on the file, no other process can get at it.

This is not the same as Unix where no locking is required and processes can see what has been written immediately.
 
If there is a possibility that two processes or threads will try to access the disk or memory mapped files at the same time, then it would be best to use synchronization, such as, CriticalSections. You would then modify the code written in the other forum, for this same question, to use this synchronization. I wrote the code in Visual C++ and ran it on a PC with the Windows 2000 operating system. I have not programmed for the unix or linux operating systems.

HyperEngineer
If it ain't broke, it probably needs improvement.
 
Hi HyperEngineer/XWB
thanks a lot for your reply. i tried out with code with HyperEngineer gave me. it is working. only thing i could not understand is that the first argument while creating file mapping object. what is the meaning of 0xFFFFFFFF means how system interprets it?

Second issue was that is it possible to create or rather share one file mapping object for two different files on the disk ? as far as my knowledge goes, sharing of view of file mapping object by threads or process is possible. i have slight confussion here on this point. how system manages the disk data with out backing it on the page file using file mapping object ?

if you can help me in knowing thsi, i will be really greatful ....

thanks in advance...

sanjay
 
Sanjay,

I'm glad the code worked for you.

Setting the file handle to 0xffffffff tells the system to create a file mapping object defined by dwMaximumSizeHigh and dwMaximumSizeLow and not a named file in the file system. In otherwords, this is a file in memory and not on the disk.


HyperEngineer
If it ain't broke, it probably needs improvement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top