For Programmers: Free Programming Magazines  


Home > Archive > VC Language > June 2005 > Cannot delete a memory mapped file at end of program









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Cannot delete a memory mapped file at end of program
Peter Nolan

2005-06-04, 3:58 pm

Hi All,
wonder if someone can point out what I am doing wrong.....I am creating
memory mapped files on win2000 using CreateFile and CreateFileMapping
and MapViewOfFile. At the end of the program I figured it would be
nice to clean up these files but when I issued the del <filename> as a
system command (or if I try the DeleteFile function) I get a message
saying that the file is in use by another process.....Is there
something else I must do to release a file that I have set up using
CreateFile and CreateFileMapping and MapViewOfFile???

Any tips greatly appreciated...




//////////////////////////////////////////////////////////////////////////////////////////////
// When the job ends deleted the wait file, the kill file, and any
memory mapped files that //
// have been created by this process.
//
//////////////////////////////////////////////////////////////////////////////////////////////
ptr_WaitFile->Delete() ;
ptr_KillFile->Delete() ;
for (index1 = 0 ; index1 < ws_used_memory_mapped_files ; index1++)
BEGIN_

#if defined (_MSC_VER)
UnmapViewOfFile(ptr_MemMapBuffer_array[i
ndex1]) ;
DWORD dw1 = GetLastError();
CloseHandle(ws_HandleForMemMapFile_array
[index1]) ;
DWORD dw2 = GetLastError();
#endif
ptr_DimensionTable_File[index1]->Delete() ;
END_

Igor Tandetnik

2005-06-04, 3:58 pm

"Peter Nolan" <peter@peternolan.com> wrote in message
news:1117907755.979354.26380@g49g2000cwa.googlegroups.com
> wonder if someone can point out what I am doing wrong.....I am
> creating memory mapped files on win2000 using CreateFile and
> CreateFileMapping and MapViewOfFile. At the end of the program I
> figured it would be nice to clean up these files but when I issued
> the del <filename> as a system command (or if I try the DeleteFile
> function) I get a message saying that the file is in use by another
> process.....Is there something else I must do to release a file that
> I have set up using CreateFile and CreateFileMapping and
> MapViewOfFile???


Both CreateFile and CreateFileMapping return HANDLEs. Both handles must
be closed with CloseHandle. You seem to only close one.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Tim Roberts

2005-06-05, 3:58 am

"Peter Nolan" <peter@peternolan.com> wrote:
>
>//////////////////////////////////////////////////////////////////////////////////////////////
>// When the job ends deleted the wait file, the kill file, and any
>memory mapped files that //
>// have been created by this process.
> //
>//////////////////////////////////////////////////////////////////////////////////////////////
> ptr_WaitFile->Delete() ;
> ptr_KillFile->Delete() ;
> for (index1 = 0 ; index1 < ws_used_memory_mapped_files ; index1++)
> BEGIN_
>
>#if defined (_MSC_VER)
> UnmapViewOfFile(ptr_MemMapBuffer_array
[index1]) ;
> DWORD dw1 = GetLastError();
> CloseHandle(ws_HandleForMemMapFile_arr
ay[index1]) ;
> DWORD dw2 = GetLastError();
>#endif
> ptr_DimensionTable_File[index1]->Delete() ;
> END_


Please tell me that you have not done this:

#define BEGIN_ {
#define END_ }

There is absolutely no justifiction for that kind of madness.
--
- Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com