Say I have a struct
struct GRAPH {
NODE* nodes[];
}
With a dynamic size for nodes[]. I also have
struct NODE {
char filename[40];
struct NODE* links[];
}
I will know how many links and nodes I need at runtime, and can calculate total required space. I know that running malloc() is runtime-costly, so doing a malloc() for nodes[], then adding the pointer from malloc() for each node would be bad.
I presume I will have to call malloc() for the total size of GRAPH, then manually handle pointers from this space, using a char* (1 byte) and saving offsets. Do I need to allocate for and handle null terminators at the end of each links[] (i.e. use calloc() with a larger size)? Is there a better way to be going about this?