I am trying to understand how memory is allocated as the number of objects increases. Following test program creates 400million objects and its memory occupancy is approximately 23GB.
Why would it occupy such huge memory while the single object size is just 16 bytes. Ideally i would assume it should be 16bytes multiplied by 400million.
struct class1 {
long long id;
double value=0.0;
class1(long long id) {
this.id = id;
}
};
for (int i=1;i<=400000000;i++) {
class1 *t = new class1(i);
}