A
against.inex
Hi,
The following code snippet when compiled using gcc 3.3.5 creates an
executable which is 6.9 KB in size.
int main(){
int arr[1000000]={0};
long arr2[100000]={0};
double arr3[100000]={0};
}
However
int main(){
int arr[1000000]={1};
long arr2[100000]={1};
double arr3[100000]={1};
}
creates an executable which is 5 MB in size. Why is there such a huge
difference when we change the initialization value? In the former all
the elements are zero while in the latter case all except the first one
are zero. In another forum someone mentioned that in the latter case
the space for the arrays is allocated in the data segment while in the
former case it is not. Is that the case? If so can anyone brief me
about how the compiler decides where memory is allocated in such cases?
Do let me know if this a just compiler issue and not related to C++ per
se.
Thanks
Priya
The following code snippet when compiled using gcc 3.3.5 creates an
executable which is 6.9 KB in size.
int main(){
int arr[1000000]={0};
long arr2[100000]={0};
double arr3[100000]={0};
}
However
int main(){
int arr[1000000]={1};
long arr2[100000]={1};
double arr3[100000]={1};
}
creates an executable which is 5 MB in size. Why is there such a huge
difference when we change the initialization value? In the former all
the elements are zero while in the latter case all except the first one
are zero. In another forum someone mentioned that in the latter case
the space for the arrays is allocated in the data segment while in the
former case it is not. Is that the case? If so can anyone brief me
about how the compiler decides where memory is allocated in such cases?
Do let me know if this a just compiler issue and not related to C++ per
se.
Thanks
Priya