storing multiple arrays within a struct in C -


i trying design data structure in c can store multiple arrays possibly in struct, each of arrays of different size. example:

typedef struct task_list {   int total_tasks;   unsigned int *task_array  }task_list;  typedef struct node_list {   int total_nodes;   task_list *array_node  }node_list; 

therefore if have 5 nodes, total_nodes 5 , wish have 5 subsequent arrays namely array_node[0], array_node[1] ... array_node[4]. each of arrays hold unsigned integers(tasks). problem each of these arrays hold different number of tasks (total_tasks in struct task_list), therefore size of each of arrays different.

how create , allocate memory each of these task array's? , best way access them later?

if 1-d arrays, best way allocate memory through malloc. again, since 1-d can access them via array notation, being careful no exceed bounds given total_nodes , total_tasks. use free free arrays when deleting nodes. if array nodes gets bigger, use realloc make array bigger , keep old pointers in place.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -