C++数据存储技术

发布于 2025-01-17 06:04:31 字数 332 浏览 1 评论 0原文

在研究了解决此问题的方法之后,我有点不知所措,因为以前从未这样做过,所以我在这里。我正在研究为个人项目存储数据的方法。我以前从未使用过这么多数据,通常只是将其存储在 .txt.csv 中,但我很好奇是否有更好的方法去解决它。我目前正在研究 json ,因为我觉得该结构在未来可能会很有用(不是那么重要)。

就数据而言,只需考虑一个字典:idx |字符串|字符串|字符串|字符串..

如果我只想通过索引抓取信息来显示,那么将所有信息存储到 DBMS 中值得投资吗?我更好奇为什么你会选择一条路线而不是另一条路线。

After looking at ways to go about this, I'm a bit overwhelmed, having never done this before, so here I am. I'm looking into ways to store my data for a personal project. I've never used so much data before, and I usually just stored it in a .txt or .csv, but I'm curious if there would be a better way to go about it. I'm currently looking into json at the moment, as I feel the structure could prove useful in the future (not that important).

In terms of the data, just think of a dictionary: idx | string | string | string | string ...

Would it be worth the investment to store all the information into a DBMS if I just want to grab it by the index to display? I'm more curious about why you'd take one route over the other.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

思念满溢 2025-01-24 06:04:32

使用像 SQLite 这样的轻量级选项,投资本身将非常有限(复杂性也如此)额外的占用空间),并且您将能够将一大堆问题转移给库:内存管理、按标准检索数据等。使用 JSON,您要么必须将整个数据集保留在 RAM 中(但这无法扩展)另外,在每次启停时,您都必须加载和保存它)并且您必须自己解决所有查询问题。

还有其他选项,但在我看来,SQLite 非常成熟、非常知名且非常可靠,如果您需要的只是纯 ISAM 风格的访问,那么您需要了解的 SQL 就很少。

With lightweight options like SQLite the investment per se will be pretty much limited (in as well complexity as extra footprint), and you will be able to offload a whole bunch of concerns to the library: memory management, data retrieval by criterion, etc. With JSON you will either have to keep the entire dataset in RAM (but that doesn't scale plus on each start-stop you will have to load and save it) and you will have to figure out querying all by yourself.

There are other options as well but in my opinion SQLite is very mature, very well known and pretty solid, and if all you need is pure ISAM style access, the SQL you will need to understand is minimal.

Oo萌小芽oO 2025-01-24 06:04:32

有数千个已经实施的标准解决方案。

  1. 正如其他人已经提到的:使用您选择的库连接到数据库。但这通常是我知道的所有库中最慢的方法,所有内容都将转换为文本以将其传输到数据库核心,有时会解析回本机数据。这会消耗大量时间和内存。

  2. 使用您自己的数据结构并使用通用序列化器。

  3. 使用库来描述您的数据结构及其 IO 设施,例如 protobuf。有很多实现。

  4. 或者干脆手工制作...但我的建议是:采用已经实施的解决方案,因为它可以节省您的时间,尤其有助于避免重新发明轮子和错误。

There are thousands of already implemented standard solutions.

  1. As already mentioned by others: Connect to a data base with a library of your choice. But this is typically the slowest method as in all libraries I know, all and everything will be converted to text to transfer it to the database core and there sometimes parsed back to native data. This consumes a lot of time and memory.

  2. Use your own data structures and use a common serializer.

  3. Use a library to describe your data structures and the IO facilities for them like protobuf. There are a lot of implementations.

  4. Or simply do it handcrafted... but my advice is: Take a already implemented solution as it saves your time and especially helps to not reinvent the wheel and bugs.

还不是爱你 2025-01-24 06:04:32

我在 ObjectBox 工作,我自己也是 C++ 新手,所以我可以说,即使您不熟悉任何数据存储解决方案,它也很容易使用。这是一个免费使用的 NoSQL 数据库。

您定义架构(一个单独的文件,列出对象的属性,例如单词本身及其定义),ObjectBox 会自动生成绑定代码。在应用程序中存储数据只需使用本机 C++ 对象即可,如下例所示:

int main() {
    obx::Store store(create_obx_model());
    obx::Box<Word> box(store);

    // Create an object
    obx_id id = box.put({.word = "entry 1", .definition = "definition 1"});  

    // Read from the database
    std::unique_ptr<Word> entry = box.get(id);

return 0;
}

架构文件如下所示:

table Word {
    id: ulong;
    word: string;
    definition: string;
}

您可以从这里开始

I’m working at ObjectBox and am new to C++ myself, so I can say that it’s quite easy to use even if you aren’t familiar with any data storage solutions. This is a free to use NoSQL database.

You define the schema (a separate file that lists the properties of your object, like the word itself and its definition) and ObjectBox generates the binding code automatically. Storing data in your app is then just a matter of using a native C++ object, like in the example below:

int main() {
    obx::Store store(create_obx_model());
    obx::Box<Word> box(store);

    // Create an object
    obx_id id = box.put({.word = "entry 1", .definition = "definition 1"});  

    // Read from the database
    std::unique_ptr<Word> entry = box.get(id);

return 0;
}

Here is how the schema file looks like:

table Word {
    id: ulong;
    word: string;
    definition: string;
}

You can get started here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文