简体   繁体   中英

C++ with fstream or database

I am trying to implement a image recognition program in C++ .

I had completed the extracted of feature, now trying to save the large amount of numbers. I had 2 implementation in mind, one is to save the data into binary files, to reduce the overhead of computation, or I can use database to keep the information.

Binary file is fast to read and write, but hard to access, while database seem an easier interface to work with, but I am not sure if the performance is fast enough.

Do you guys have any experience regarding fsream or database as the choice for fast persistent storage?

You could use SQLite . It basically gives to database-style access to local files. You can also create in-memory databases with it, but i do not know if it is possible to persist those.

Also, the best choice here heavily depends on your access patterns. If it is just sequenctial write and sequential read, then binary files are the best solution.

如果您确实想要速度,请考虑使用C型I / O函数,例如fopen(0,fread()等)。由于多种原因,这些函数通常比iostream更快。

For me the advantage of using a database like SQLite is an independant format for my data and the ability to query the data using SQL.

Writing data to a SQLite database proved to be a lot slower than writing it to a simple CSV text file.

It depends what you want to do with the data afterwards? If you simply want to read it in again and do some stuff, use fstream (or C-style I/O) like suggested. If you want to query the data and only get specific data, use SQLite.

You also have to consider how you wish to store the data in a database. If you are going to store the data as a BLOB, you may end up losing the benefits of SQL and sacraficing performance.

I am writing an audio recognition program in C++, and I am using now PostgreSql for data storage. So I am interested in an answer too :). What I can propose is that, the data storage should be chosen according the recognition algorithm. If you compare your image with saved images 1 by 1, then binary files seem to be quicker. But if during recognition you work with several images at once, a database may be more speedy solution.

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