JiiPee <no@notvalid.com> wrote in news:Ie1Mw.381530$dX1.143786@fx21.am4:
int size = 10;
int* a = new int[size ];
float* b = new float[size ];
double* c = new double[size ];
This is not exactly equivalent to std::vector because the capacity and
efficient dynamic resizing are missing.
so in C we need total : 4 bytes overhead
16 bytes, if you want to compare correctly. Each pointer is an overhead.
And if you add capacities, it will make 28 bytes.
in C++:
vector<int> a = ...10);
vector<float> b = ...10);
vector<double> c = ..10).;
would need total: 36 bytes of overhead
If the vectors are always of the same length, then the solution is
clear:
struct X {
int a;
float b;
double c;
};
std::vector<X> x;
Voila: this has 12 bytes overhead, which is 4 bytes less than the C
version, plus it supports efficient dynamic resizing as a bonus, plus it
is not error-prone and exception-unsafe - an even bigger bonus. Q.E.D.
You could of course have a dynamic array of X also.
everything else..