Created
March 24, 2019 07:11
-
-
Save BriFuture/d9d7b153e2c5d3bacdeb1302668553ca to your computer and use it in GitHub Desktop.
QFile map file into memory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QCoreApplication> | |
#include <QFile> | |
#include <QDir> | |
#define Size 150 * 2096 | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication a(argc, argv); | |
QDir dir; | |
dir.mkdir("video"); | |
QString fileName = dir.absoluteFilePath("video/test.dat"); | |
QFile file(fileName); | |
file.open(QFile::ReadWrite); | |
uchar colors[Size]; | |
for(int i = 0; i < Size; i++) { | |
colors[i] = uchar(i); | |
} | |
file.resize(Size); | |
uchar *filemap = file.map(0, Size); | |
memcpy(filemap, colors, Size); | |
file.unmap(filemap); | |
file.close(); | |
return 0; | |
// return a.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment