大家好,又见面了,我是你们的朋友全栈君。
最近在看代码的时候发现了Qt的内存映射,原来只知道MFC有内存映射机制,可以在读取大数据文件时节约读取的时间,原来Qt中也有相应的机制,其用法更简单,下面用一个小例子演示其用法
#include <QtCore/QCoreApplication>
#include <QFile>
#include <QDebug>
#include <iostream>
#include <stdio.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QFile file("1.txt");
file.open(QIODevice::ReadWrite);
qDebug() << QStringLiteral("内存大小:") << file.size();
uchar *fpr = file.map(0, file.size());
int i = 0;
int x1 = 0, x2 = 0, x3 = 0;
char *pEnd1 = NULL;
char *pEnd2 = NULL;
char *pEnd3 = (char *)fpr;
for (int i = 0 ; i < 3 ; ++i)
{
x1 = strtod(pEnd3, &pEnd1);
x2 = strtod(pEnd1, &pEnd2);
x3 = strtod(pEnd2, &pEnd3);
std::cout << x1 << "," << x2 << "," << x3 << "\n";
}
file.close();
return a.exec();
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/151691.html原文链接:https://javaforall.cn