文本文件与大存储在openGL

Text-file with large storage in openGL

本文关键字:openGL 存储 文件 文本      更新时间:2023-10-16

我正在编写一个程序,它必须存储对象的位置。这个数据可以达到100MB以上,我想把它存储在硬盘上。现在,我搜索了一下,有几种方法可以做到这一点:txt-file, sql, xml,…

我已经知道如何在c++中制作文本文件。但是,.txt文件存储大量数据的优势是什么呢?最好的方法是什么?

目前我逐行存储数字,所以我可以用getline()读取它。但它给我带来了问题,它读起来不太好。也许是因为。txt不能处理很多数据,也许是因为逐行读取很慢,这给我带来了问题。有人知道怎么解这个吗?

下面是一些代码:
    _chdir("c:/Documents and Settings/Bram/Bureaublad/cloth3d");
    ofstream mfile;
    mfile.open("example.txt", ifstream::out);
some calculations...
        mfile << (double) vervangplaats[i][j][0] << "n";
        mfile << (double) vervangplaats[i][j][1] << "n";
        mfile << (double) vervangplaats[i][j][2] << "n";
// the data is stored in the .txt file
mfile.close();

将数据存储在TXT文件中现在我把它提取出来。

std::string b;
ifstream file("example.txt", ifstream::out);
if(file.is_open())
{
        getline(file, b);
    result[0][teller_x][teller_y] = (double) atof(b.c_str());
        getline(file, b);
    result[1][teller_x][teller_y] = (double) atof(b.c_str());
        getline(file, b);
    result[2][teller_x][teller_y] = (double) atof(b.c_str());
}

最后一个带有getline的函数在一帧中使用2500次。

并且帧不加载,可能是因为每帧的getline量很高,或者只是因为txt不适合存储太多数据?

嗯,每帧从磁盘加载数据从来都不是一个好主意,那将会太慢。在开始渲染之前,必须将数据加载到内存一次

也就是说,文本文件最适合于需要人类可读和可移植的数据。

像这样的低级数据通常以二进制形式存储,这使得文件更小,加载更简单,更快。