A
Allin Cottrell
A. Suppose my program mallocs and populates an array of structs
of a fixed size apiece. For example, something like:
struct foo {
int i;
double x[8];
char s[16];
};
We want to save this work and re-read it later. One solution
that works well -- so long as we're sure the re-reading will
occur on the same platform as the saving -- is to do a binary
dump of the array of structs with fwrite(), then read them
back into memory later with fread().
B. Now suppose my program mallocs and populates an array
of structs which themselves contain dynamically allocated
members, for example
struct baz {
int i;
double *x; /* size of array unknown at compile time */
char *s; /* length of string unknown at compile time */
};
Question: Is there any fancy footwork which will permit the
use of a similar approach to case A -- in terms of fwrite()
and fread() -- in this second case?
Allin Cottrell
Wake Forest University
of a fixed size apiece. For example, something like:
struct foo {
int i;
double x[8];
char s[16];
};
We want to save this work and re-read it later. One solution
that works well -- so long as we're sure the re-reading will
occur on the same platform as the saving -- is to do a binary
dump of the array of structs with fwrite(), then read them
back into memory later with fread().
B. Now suppose my program mallocs and populates an array
of structs which themselves contain dynamically allocated
members, for example
struct baz {
int i;
double *x; /* size of array unknown at compile time */
char *s; /* length of string unknown at compile time */
};
Question: Is there any fancy footwork which will permit the
use of a similar approach to case A -- in terms of fwrite()
and fread() -- in this second case?
Allin Cottrell
Wake Forest University