This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
how to use malloc to reserve space for 1 million floats
- From: Anna Sidera <sidera dot anna at ucy dot ac dot cy>
- To: gcc-help at gcc dot gnu dot org
- Date: Mon, 27 Aug 2012 12:40:51 +0300
- Subject: how to use malloc to reserve space for 1 million floats
Hello,
I want to use the following command:
int myvariable = 1000;
float *myarray = malloc(pow(myvariable,3)*sizeof(float));
but I don't know if it will work because if sizeof(float) is equal to 4 then pow(myvariable,3)*sizeof(float) is equal to 4 billion which is larger than the maximum integer which is about 2 billion.
Can you tell me what is the right way to create an array of pow(myvariable,3) floats?
Many Thanks,
Anna