Question:
C++ Setting up In Memory Database using Arrays of Structs?
Marcus Stevens
2011-01-30 12:32:42 UTC
So I spent a while over the past few days writing some bank software for class, however I did this using records stored on the disk and apparently it needs to be an in-memory database using an array of structs. At least according to a line near the end of the instructions:
Implement your database as an array of structs of Bank Customer Record.
Which doesn't make any ******* sense to me but whatever.

I've never really done an in-memory database before so I'm a bit lost.

So to create and save the data, I used a struct and then just wrote the data to text files that I saved in a folder based on a sequential numbering system (the first created file was 0, then 1, 2, 3, etc), and to search the records it just opened the files and scanned the first two lines searching for a match to the name.
Because we also need to keep a log of transactions, I had four other files (one of them added a new line with information on a withdrawals, another on deposits, and a third that kept track of money transferred between accounts, and then a last on that changed a float every time there was a withdrawal or deposit).

Now, I think it will likely be a lot more complicated to do in-memory. So I'm hoping someone can link me to a tutorial on doing something like this, or explain part of it.

Can I set up a struct inside an array? How do I log and recall specific data, or run searches and whatnot of it all if it's not stored in a file? Would I need to make the entire thing in main() so that I can (can't use global variables, only constants)?

Am I even thinking of what it is right?
Three answers:
anonymous
2011-01-30 12:50:44 UTC
Which compiler you use?



If it is Borland Compiler there are many in-memory dataset providers available.



If you are using ADO there is Simple Data Provider that does in memory databases. Please check out!



Here is a useful link: http://www.google.com/url?sa=t&source=web&cd=6&ved=0CDwQFjAF&url=http%3A%2F%2Fmsdn.microsoft.com%2Fen-us%2Flibrary%2Fms675260(v%3Dvs.85).aspx&ei=XM5FTfq_DIzsrQeT1Zww&usg=AFQjCNEIFz3NyBZ_lO8_dt5kaPuZwpAo3A







]

.
Myke
2011-01-30 12:57:34 UTC
Wow. This can be tough. I'm hoping your instructor is not expecting even a low featured in memory database which is capable of performing JOINs, etc - in other words, that your DB needs to understand SQL - that could be quite an assignment.



Since you're talking about holding structs in arrays which are held in dynamic memory, I suspect the set of DB instructions would be limited to INSERTs, UPDATEs, DELETEs and SELECTs. These are your basic DB operations. So, given this, you need a class that provides those operations. The internal implementation of the class needs to maintain all of its data in dynamic memory (so, not on a file, and OMG, not in constant variables LOL).



Yes, you can make an array of type struct. Just like you can make an array of int (assuming you're using C/C++). If then number of struct entries in your DB can be variable, then your 'array' may also need to be dynamically allocated (and capable of being resized in memory if it grows beyond its initial limited size). Of course, you'd hide all these details in your class.



If you're not sure about what I wrote... then maybe you're just getting into arrays and starting to use them in a more real-world application, and that's OK... if that's then case then just ignore what I said.



An array of struct (using C/C++ syntax):



typedef struct {

string accountName;

float balance;

} AccountType;



AccountType *myAccountDB = new AccountType[50]; //<<< this is an array held in memory.
lopes
2017-01-08 14:36:54 UTC
merely outline a typedef struct which incorporates the fields you want for one among your database archives, then allocate an array of those structs - voila - one in-memory database.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...