a problem with a memory management

This is a discussion on a problem with a memory management within the C Programming forums, part of the General Programming Boards category; Hi
I decided to program a cd database application with a binary file database. With this app i can add ...

a problem with a memory management

Hi

I decided to program a cd database application with a binary file database. With this app i can add to and remove cds from the database, edit information in the database, view the cds in the database and search information from the database.

I'm a beginner and i have done only few little programming projects. Now i'm a bit lost how i shoud implement the memory management for this app. Should i use a linked list here? What's the professional way to do this? Thanks a lot!

Start with a fixed length array. It will allow you to get a lot of the logic working correctly without complicating the logic.

Thanks for the reply. Do you mean that, if i have a database which consist of an array with eg. 200 structs in it, i should allocate memory to an array for an array with 500 structs what's the max length of my array? I mean in which parts of the program i should do the memory allocation? Is it just before i start to read data from the file to the memory?

This falls slightly outside the realm of your initial question, but I remember using this in a project I did about five years ago. Its called Gracenote these days (and looks like a pain in the neck to use unlike its past incarnations).

And as far as your question to Salem goes, get your code working within a very controlled environment, then start doing the complicated stuff. Far too often people try to sort out their memory manager while writing their code. Not knowing the effectiveness of their code, nor their memory manager, debugging the code becomes a grueling nightmare. So keep things simple. And as you perfect one area of your program, then work on the other.

Then make this a global variable (yes, I know global variables are evil, but in this case there will only be ONE database, and making it global should be OK):

Code:

#define MAXCDS 200
struct CDEntry cddatabase[MAXCDS];

Then work out how you store your CD's to a file, enter new data into the database, find a CD by title, artist etc, delete entries, export as Excel spreadsheet, etc, etc.

For the future:
If you want to really do this the DATABASE way, then the artists should be in a "artists" table, the CD entries in a "cd" table, and you probably would need a few more tables (such as "label"). But now you need a proper (relational) database engine to solve the problem.

On the other hand, that's like building a top-league (F1, Indycar, WTCC or World Rally Series) race-car, when you have no experience whatsoever in building/modifying cars - it would be much better to start by building something like a gocart, because with suifficient DIY skills, that CAN BE DONE - so start with a basic database design that you can add, delete and search. Once you have a fair understanding of how it should work, it becomes a much easier task to take it to the next level (which of course is far from the TOP LEVEL).