struct counterpart {
int ncp; /* number of elements in cp */
int *cp; /* array with ncp elements */
};
struct counterpart_array {
size_t nobj; /* number of objects looking for cp(s) */
int *ncp; /* array of number of counterparts */
int **cp; /* array of counterpart pointer */
};The major difference between this two structs is that the block of the memory is segment or not. For the yellow case, we have to allocate an array of the structs with nobj (number of objects). Each cp needs allocating with one element as default. Therefore, the locations are separated in the memory. It might reduce the efficiency of computing.
The green case might work only if we create *cp in an order, i.e. element(s) follows the previous element.
Actually, I thought another way to do this
struct counterpart_arr {
size_t nobj; /* number of objects looking for cp(s) */
int *ncp; /* number of cp(s) found with the order of obj */
int *cp_index; /* array of cp index */
};

No comments:
Post a Comment