- If you must be prepared to store a large number of structure objects in
the worst case, and the expected number of structure objects is much
smaller and you want to conserve memory, then define an array of pointers
to structure objects instead of an array of structure objects.
- If you want to create a one-dimensional array of structure-object
pointers, then instantiate the following pattern:
struct structure name *array name [number of objects];
- If you want to allocate a chunk of memory to a structure object at run time,
and you want to refer to the address of that chunk of memory
in a pointer array,
then instantiate the following pattern:
array name[index]
= (struct data type*)
malloc (sizeof (struct data type));
- If you want to write a value for a structure variable in a structure
object,
and you have an array that contains a pointer to that structure object,
then instantiate one of the following patterns:
/* OK: */
(*array name[index]).structure variable's name = expression;
/* Better: */
array name[index] -> structure variable's name = expression;
- If you want to access a structure variable in a structure object,
and you have an array that contains a pointer to that structure object,
then instantiate one of the following patterns:
/* Ok: */
(*array name[index]).structure-variable name
/* Better: */
array name[index] -> structure-variable name