Home > database >  How to save classes and vectors for later, so I don't have to create them every time I start my
How to save classes and vectors for later, so I don't have to create them every time I start my

Time:10-27

I have a .txt file with millions of Data points, and I want to organize them into Classes and Vectors. So the data is usable. However this will take a very long time and I don't want to do it every time I start my program. Is there a way to store the created classes and the data inside them so I only have to go through this process once?

This is my first attempt at a practical program, so I apologize if this is a stupid question. If you could just point me in the right direction I would really appreciate it.

CodePudding user response:

It sounds like a premature optimization to me. You say it "will take a very long time", but have not quantified that. How long does it take (as a function of data size), and what are your performance requirements? It sound like you have not yet written this code, so have no real idea of the actual performance. If this is your first substantial C project, the techniques necessary may be too advanced, and the benefit may not be realised.

One solution could be instantiate your objects in memory mapped files, and restore them using placement new. However unless the construction, processing and transformations required to load the text file into the data structures is significant, I doubt the complexity of that would be justified by the result.

Simply serialising the data into a binary rather than text file so that in re-reading it, fewer conversions are required could be a far simpler method. That is to say, you could rewrite the data file in a form that can be more efficiently and directly re-loaded subsequently. You would then write your code to be able to read either format, and generate the optimised format from the text format.

CodePudding user response:

I think it's not possible because your data needs to be loaded into RAM in order for you to work with it. And it will take a long time anyway.

But you can reduce the load time if you know the size of the array. Initialize it with a specific size instead of using push_back() because this method takes more time. Also you can try binary writing to your file, it will reduce file size and download time.

  • Related