Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

General 3 Dim Array Memory Allocation Question

Status
Not open for further replies.

itdamon

MIS
Mar 18, 2002
69
US
Hi,

I have a general memory allocation question, this topic came up at work and everyone has different answers.

If I have an integer array of 3 dimensions, with each dimension having 1000 elements, on a 32 bit system, how many bytes does it take to create this array?

I'm thinking it would be 1000 * 1000 * 1000, (1,000,000,000 spaces? ...this can't be right! 4 bits for an integer would be like 4 billion bytes!)

Just kinda curious.
 
Oh, I'm using the sizeof function to try and evaluate this question, the compiler tells me one thing, and my brain is trying to tell me something else. I think I'm missing something here.

#include <stdio.h>

int intArray[100];

/* Not sure how big array size is, so I'll use long data type to be safe. */

long int_3D_100_Array[100][100][100];

long int_3D_1000_Array[1000][1000][1000];

void main(void){

printf(&quot;Size of int data type = %d bytes.\n&quot;, sizeof(int));

printf(&quot;Size of long data type = %d bytes.\n&quot;, sizeof(long));

printf(&quot;Size of a int[100] arrary = %d bytes.\n&quot;, sizeof(intArray));

printf(&quot;Size of a int[100][100][100] array = %d bytes,&quot;, sizeof(int_3D_100_Array));

printf(&quot; or %d Kb.\n&quot;,(sizeof(int_3D_100_Array)/1000));

printf(&quot;Size of a int[1000][1000][1000] array = %d bytes,&quot;, sizeof(int_3D_1000_Array));

printf(&quot; or %d Kb.\n&quot;,(sizeof(int_3D_1000_Array)/1000));

}
 
of course you are right 1000 * 1000 * 1000 *sizeof(int) is the result.
i.e. 4 * 1000 *1000 *1000.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top