struct ... many of them

hello.
i would like some piece of advice regarding how to look into my problem.
i've got this struct {} which contains some integers and 1D pointers, for example:

typedef struct var {
long n;
double a[n], b[n], c[n] ;
} cell ;

the fact is i need about 1-10 millions of these cells, and each cell has different values for 'n',and these values change over time.

it is clear to me i have to use pointers and dynamically alocated memory for this (or else.. segmentation fault) , and that's why i need some piece of advice of how to do it right (basicaly).

any insight is apreciated.
thank you for your time
better use std::vector for a - c. http://www.cplusplus.com/reference/stl/vector/
Then you don't need to hassle with dynamic allocation. But be aware that vectors grow only automatically when you call the function push_back()
i forgot to mention i am not familiar with the C++ language, but with the C language
so, the best way, i guess, is to use pointers ? doesn;t this mean i have to reallocate the whole memory block each time 'n' changes ?
i cannot predict how big will grow or how small it will get.
and also, the number of cells does not change during the run; i do not need linked lists, i guess. maybe " cell *p ; " will do ? and then to obtain values just use " p[i].a[j] " ?
so, the best way, i guess, is to use pointers ?
Yes
doesn;t this mean i have to reallocate the whole memory block each time 'n' changes ?
Yes. If you use malloc() to get the needed space (e. g. a = (double *) malloc(n * sizeof(double));) you can use realloc() if you need another size.

maybe " cell *p ; " will do ? and then to obtain values just use " p[i].a[j] " ?
Yes.
Topic archived. No new replies allowed.