0

From the given situation, we can say that we are able to declare array of structure in different ways. As I conclude, the difference is space optimization, namely the following:

struct { /* 1600 bytes */
    int a, c, e;
    char b, d;
} array_of_struct [100];

As is indicated at the top of the code, this takes up 1600 bytes. While this one

struct { /* 1400 bytes */
    int a[100], c[100], e[100];
    char b[100], d[100];
} struct_of_array;

takes only 1400 bytes. My question is that, when we are using such kind of things in real applications, is there any semantic difference between them? Optimization is good, but is it possible to change the main idea of code, when we declare array of structure into different forms?

Bart
  • 19,692
  • 7
  • 68
  • 77
  • 2
    Choice of AoS versus SoA is an important optimisation topic, but usually in the context of memory access patterns rather than memory usage. – Paul R Apr 19 '12 at 10:09
  • It is unclear to me what question you would actually like us to answer? Could you perhaps clarify? – Bart Apr 20 '12 at 04:46
  • ok which one is better to use in real application?first or second? –  Apr 20 '12 at 06:26

0 Answers0