Windows: moving a file that was previously mapped in memory fails

Asked
Active3 hr before
Viewed126 times

3 Answers

windows
90%

Making statements based on opinion; back them up with references or personal experience.,Stack Overflow en español, Meta Stack Overflow ,Stack Overflow em Português

In Sun's JDK, you can test that this is indeed the culprit by forcibly destroying the mapping just before doing the file move:

import sun.nio.ch.DirectBuffer;
import sun.misc.Cleaner;
[...]
if (byteBuffer.isDirect()) {
   Cleaner cleaner = ((DirectBuffer) byteBuffer).cleaner();
   cleaner.clean();
}
// move file
88%

I need to use memory mapped file but I am not able to prevent the error below on Windows.,In Sun's JDK, you can test that this is indeed the culprit by forcibly destroying the mapping just before doing the file move:,In Java, file mappings are garbage collected, and there is no supported way to forcibly destroy a mapping.,The error message says it all. Windows can't delete or rename an open file like any Unix can, and you're opening workFile and then immediately trying to rename it. You'll have to close the stream first.

load more v
72%

1.3 Windows Growable Memory-Mapped Files (GMMF),1 History 1.1 TOPS-20 PMAP 1.2 SunOS 4 mmap 1.3 Windows Growable Memory-Mapped Files (GMMF) ,Two decades after the release of TOPS-20's PMAP, Windows NT was given Growable Memory-Mapped Files (GMMF). ,^ "Memory-Mapped Files". Boost.org.

SunOS 4 mmap[edit]

SunOS 4[5] introduced Unix's mmap, which permitted programs "to map files into memory."[1]

mmap
load more v

Other "windows-undefined" queries related to "Windows: moving a file that was previously mapped in memory fails"