I would like to know how to allocate sequential memory for an array of structures inside another structure. Say I have struct1 that has an array of struct2, I would like to have it all in one consecutive block of memory.
I could use malloc to allocate a block, but how would I assign an array memory?
struct1 *set = malloc(sizeof(struct1) + sizeof(struct2)*number_of_structs); set->arr = (struct2*)set + sizeof(struct);
Thanks.
source share