Jump to content

Talk:Parallel array

Page contents not supported in other languages.
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Elnyka (talk | contribs) at 21:36, 19 September 2011 (Simpler to understand?: new section). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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*/};

Kasajian (talk) 09:57, 9 December 2009 (UTC)[reply]

Simpler to understand?

Hi, I've a bit of a problem with the following statement:

Parallel arrays are simple to understand and use, and are often used where declaring a record is more trouble than it's worth.

I know that this is purely annecdotal, but I've worked in code that makes heavy use of parallel arrays instead of records (or similar data types), and it is a nightmare for anything but the most trivial. So, how exactly parallel arrays are simple to understand? How would one go about qualifying and quantifying such a statement? Maybe such a statement should be accompanied by some type of code sample comparisons (using parallel arrays and record types). Nevertheless, I'd be very hard press to find an example where, conceptually, the former is simpler to understand than the later.