Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
During the run of my c++ program I have an amount of data that I will use.
I want to be able to use some of it depending on some criterion. In other words, a kind of data base with request instructions.
Is it possible to create an internal database and use it with DB request instructions?
I don't need to save the data either before or after the run.
Edit:
It won't be feasable in my case to add other C libraries, I'll have to work with what i'm provided with.
You may like to have a look at SQLite in-memory database.
Alternatively, use a container with one or more indexes, e.g. boost::multi_index.
You can use some database theory:
1. Store all the records into std::vector.
2. Use std::map to build search / index tables.
The index tables will give you quicker search times on keys without having to sort all the data. The index table will be of the form std::map<Key_Type, unsigned int>, where the unsigned int is the index into the std::vector database.
You can use a in memory structure, depending on how big this database needs to be. Is it a collection of Structs or is it a proper relational database or just tons of unstructured data?
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 10 months ago.
Improve this question
I have a problem where I need to sort buses arriving at a bus station on the basis of time of arrival without using STL (standard template library) in ascending order
You may first want to read about sorting algorithms in general. A good staring point is here.
There you see many of them.
The recommendation for newbies is to start with bubble sort.
Please see here for an example including source code.
Then, you need to store your bus data in a struct. Along with the timing information. All those struct shoulb be stored in an array, best a std::vector.
Then you need to write a compare function for times. The complexity of this depends, if you have one varaible that stores the complete time, like in a unix timestamp, or in a struct, for example tm. Then you need to compare hours, minutes and seconds and some boolean relation.
But first, you need to read a lot, then think even longer on how to implement, and then write the code.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I’m kind of confused how flat buffers work.
I tried looking at the docs but am still confused.
Basically, what I need to do is
Load JSON data (or actually, ANY data format as long as it’s changeable by another user and readable) from a file into a struct or read the fields one by one.
Save the struct back into any readable data format as a file once the app closes
That’s why I’m confused on flatbuffers.
How do you change the file once it’s saved? Is the saved result binary? Or is that not what it was built for?
I’m using RapidJson currently.
The usage is read text data into a struct, when app ends save struct into text that’s modifiable.
Flatbuffers are a compact binary representation of a given data structure, with the promise that it can be used "straight from the wire", without any deserialization after the fact. By contrast, protocol buffers fill the same niche but need to be (de)serialized.
For your purposes, just stick with JSON or YAML, since "readable by humans" is a priority.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i need some help in deciding which data structure i should use. i'm going to create a patient information system of a hospital just like a simple student information system.
i have studied Arrays, Linked Lists, Trees, Stacks, Queues and Graphs. i think it would be too simple with Array. should i use linked list?
how will i store all the fields into it? a Linked list stores one item of data at the moment, no? my requirements are to add information, search them by their ID and be able to delete through ID as well.
any ideas? thanks
my requirements are to add information, search them by their ID and be able to delete through ID as well.
Seems like an std::map<id, patient> would suit your needs via:
operator[] to add a record
at/find for retrieval
erase for removal
If you need more complex queries I'd recommend a full-fledged relational database.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I want to store huge amount of trading data (say million records per day) using some kind of data base. Each record is small and has static structure: id(integer), time stamp(integer), price(float), size (float). Id field is primary key here (in terms of relational data bases). And I want to select records from specific time range (ordered by time). These is straightforward in a relational database.
Is nosql data base (DynamoDB in particular) suitable for these requirements? Or should I use traditional relational database solution ?
I don't have any experience with NoSql data bases.
The straightforward answer to this question is yes, this fits DynamoDB's use case well. But there's a better answer: try it out and see!
I have been seeing a lot of this kind of question regarding AWS, namely "will this work?" as opposed to "how do I do this?" And the best way to answer that is to try it out and see. Unlike traditional IT, you don't have to do a lot of planning or invest a lot of capital up front to try it out. Spend a buck or two (literally that little) to run a little test program using DynamoDB and another using MySQL (or other RDBMS) and see how they work for you.
Dynamodb would work, however given that each record is small, static structure in my opinion, a relational database would be equally well suited for this task, perhaps even better (which is very subjective).
Don't forget to calculate the costs of both solutions; you can easily install mysql (free) or sql server (not free once you get past a certain point) on an ec2 instance and you will know exactly what your monthly costs will be.
Dynamodb is priced very differently, so you really need to quantify your reads/writes and storage requirements in order to know what you are in for. Best to figure these things out ahead of time unless money is not a concern.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I want to build a simple program that searches through a local database and returns a list of results. Essentially the program will be a searchable archive. This will be my first project of this type and I'm looking for some advice.
Fast reading of the database is important. Writing can be slow.
There will be at most a few thousand records, and most records will probably contain less than 3 kb in text.
Records should be flexible when it comes to their fields. Some records will have the field "abc", others will not. The number of fields per record may vary.
Should I simply write my data structures in C++, and then serialize them? Does it make sense to use an existing (lightweight) database framework? If so, can you recommend any that are free and easy to use and preferably written in modern C++?
My target platform is Window and I'm using the Visual Studio compiler.
Edit: the consensus is to use SQLite. Any recommendations as to which of the many SQlite C++ wrappers to use?
As commented by #Joachim, I would suggest SQLite. I have used it in C++ projects and it's straightforward to use. You basically put two files in your project sqlite3.c and sqlite3.h and then start coding to the interface (read the last paragraph of http://www.sqlite.org/selfcontained.html). You don't have to worry about configuring a database server. It's fast and lightweight. Read about transactions and SQLite if you need to speed some operations up.