Hey
Here's an example of how I've been allocating structs:
and it seems to work ok. I was wondering what this would look like in memory though - I'm assuming that each inner *b array will be scattered. So my question is, does this reduce performance, and is it possible to allocate a single dynamic block for the whole outer *A structure?Code:typedef struct outer { char n; inner *b; } outer; typedef struct inner { float foo; int bar; } inner; int i, j; outer *A = malloc(sizeof(outer) * 100); for(i = 0; i < 100; i++) { A[i].b = malloc(sizeof(inner) * 1000); }
Many thanks
Gib