简体   繁体   中英

how can i read file fastest way in c++ ? to send data to 'Vertex Buffer Object

i have 4-5 gigabyte ".obj" files like:

Sword_1 folder has 2000 obj files , Sword_2 folder has 2000, Dagger_1 folder has 2000 ... etc totaly i have 4-5 gigabyte ".obj" files.

files contents these :

v 16.418303 40.112064 0.078153

vt 0.445198 0.462720

vn 0.264392 0.654428 0.708394

f 27/72/32 38/73/43 23/74/13

they are classic texts

and i am reading each them like this:

char text[10000][60];
ifstream in(filename);
if(!in.is_open())
{
    return false;
}
while(!in.eof())
{
    in.getline(text[i],60); 
    i++;
}

after read one folder i am sending datas to 'VBO'.

all files take 10 minutes to complete. when i make multithreading with '3 thread' (my cpu 4core 4 thread) , then same process take 3-4 minutes to complete. but still too long.

how can i make it faster ?

if i need to use binary, how can i read binary with c++ ? can you make example for me :) because i don't know anything about binaries. and if i made binary i needed to convert 'char' format ? and if i need to convert, convert process will take same minutes to complete ? sorry for bad english.

There is no "precise final answer to your question", once it depends on a couple variables here.

C++ defines the standard library "interfaces" but it doesn't precisely define the underlying implementation. It means that getline() depends on the compiler you are using and the operating system as well. So you would have to test this comparing with other ways your operating system offers to you (example, using fopen() directly, or open() in Linux/Unix environments, or OpenFile() in Windows).

Reading binaries would probably make you software faster, once you don't spend time converting the strings to numbers. One (among many) motivations for glTF .

Reading binaries is easy. But you should have a "strategy" to parse it effiently to solve your specific problem. Considering that you are trying to parse a model, I would highly suggest you to look for glTF . In glTF you can have the vertices of your 3D model in a binary format in sequence ready to feed your VBO... :-)

Google for it and learn a little more.

About reading binary data in C++ is easy:

std::ifstream file("somedata.obj", ios::binary);
if (file)
{
  char buffer[1024];
  file.read(buffer, sizeof(buffer));
  // buffer has you binary data... you can interpret it!
}  

But again, this is not enough. You need to wisely interpret the data you just read.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM