Talk:Parallel array
Appearance
I'm not sure I follow the logic for one of the advantages mentioned:
- If the number of items is small, array indices can occupy significantly less space than full pointers, particularly on architectures with large words.
Let's assume In the case of the C code, the non-parallel array version would use a struct like so:
struct person_t { int age; char* name; int parent; };
struct person_t person[] = { { 0, "None", 0 /*None*/ }, { 17, "Mike", 3 /*Tom*/ }, { 2, "Billy", 1 /*Mike*/ }, { 52, "Tom", 0 /*None*/ }, { 25, "Stan", 3 /*Tom*/ } };
Assume a 64-bit system, where pointers are 8 bytes long, whereas indices for this array can be a byte (because there's only 5 items), why would the above data-structure take up more space than the parallel array version:
int ages[] = {0, 17, 2, 52, 25}; char *names[] = {"None", "Mike", "Billy", "Tom", "Stan"}; int parent[] = {0 /*None*/, 3 /*Tom*/, 1 /*Mike*/, 0 /*None*/, 3 /*Tom*/};