Hello everyone,
I'm using a memory mapped file through a QFile object and its map() method. Works like a charm so far -- until I'm doing a resize() of the file. After that, map() always results in "Access is denied".
Maybe I'm doing something wrong, but I've tried every conceivable combination of unmap(), close(), open(), resize(), flush() I could think of. I know that the resize works, since size() reports the correct size after the resize and its size on disk is also correct. unmap() returns true. open() returns true. resize() returns true. But as soon as I want to map() the whole file (we're talking 128kB here), I get an error. I can, however, map() to the original file size... Cache problem or something?! No idea what I'm doing wrong.
Heres the method with which I try to extend the mmap'd file:
void xxx::Extend()
{
file.unmap(mmap);
file.resize( file.size() + PAGESIZE );
// Doesn't seem to be necessary
file.close();
// After this, mmap == nullptr, except parm size of map() is <= original file size
mmap = file.map(0, file.size());
// This prints "Access is denied"
qDebug() << file.errorString();
}
void xxx::Extend()
{
file.unmap(mmap);
file.resize( file.size() + PAGESIZE );
// Doesn't seem to be necessary
file.close();
file.open(QIODevice::ReadWrite);
// After this, mmap == nullptr, except parm size of map() is <= original file size
mmap = file.map(0, file.size());
// This prints "Access is denied"
qDebug() << file.errorString();
}
To copy to clipboard, switch view to plain text mode
Thanks a lot in advance and best regards!
Edit: OS is Windows 7 64bit, Qt 5.1.1 and MinGW 4.8.0
Bookmarks