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 Kasajian (talk | contribs) at 09:57, 9 December 2009 (Created page with '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 p...'). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

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]