I'm really stuck on this one. ex17 is supposed to be teaching me heap and stack memory allocation by providing a simple database (my questions are specific, but i'll leave it there just in case you need a full code). There is not much explanation about what is the purpose of certain design decisions of the database and that's why i seek for help.
1) Necessity or just a design convenience (convention) ?
struct Address {
int id;
int set;
char name[MAX_DATA];
char email[MAX_DATA];
};
struct Database {
struct Address rows[MAX_ROWS];
};
struct Connection {
FILE *file;
struct Database *db;
};
I'm not sure why there are three structs. further in the code there are expressions like (hope you understand the names of the variables) conn->db->rows[i]. My question is are three of those necessary? I mean, why do we need a connection struct for instance? Why not just create a standalone FILE *file thing and avoid a struct Database *db pointer completely?
2) Probably this will help me with the first one.
In the Extra credit aka (make it yourself) part of the exercise there is a task which reads as follows: Try reworking the program to use a single global for the database connection. How does this now version of the program compare to the other one? So is this simply asking me to rework the "3-structure-way" of managing this database?