What's about the size of memory usage?
-
I have written a program, in which, I declared a global variable such as:
typedef struct{ char buff[20]; } my_struct; my_struct my_arr[1000][30][10][10][3];
In particular: the size of my_struct is 20 bytes. My calculation showed that the size of my_arr variable is: 1000*30*10*10*3*20=180.000.000 bytes or close to 180M. But when I run that program, Task Manager showed me the program took only 3MB (in Mem Usage column). When I started to fill data into my_arr, Mem Usage increased very quickly and program terminated abnormally. Does anyone explain me about that situation? I used VC6 and MFC. Thanks for reading. -
I have written a program, in which, I declared a global variable such as:
typedef struct{ char buff[20]; } my_struct; my_struct my_arr[1000][30][10][10][3];
In particular: the size of my_struct is 20 bytes. My calculation showed that the size of my_arr variable is: 1000*30*10*10*3*20=180.000.000 bytes or close to 180M. But when I run that program, Task Manager showed me the program took only 3MB (in Mem Usage column). When I started to fill data into my_arr, Mem Usage increased very quickly and program terminated abnormally. Does anyone explain me about that situation? I used VC6 and MFC. Thanks for reading.May be it was optimised by the compiler and may be windows too. so as and when you started filling up the data memory was allocated to it.. nguyenvhn wrote: When I started to fill data into my_arr, Mem Usage increased very quickly and program terminated abnormally. may be you overshot the buffer.
God is Real, unless declared Integer.
-
I have written a program, in which, I declared a global variable such as:
typedef struct{ char buff[20]; } my_struct; my_struct my_arr[1000][30][10][10][3];
In particular: the size of my_struct is 20 bytes. My calculation showed that the size of my_arr variable is: 1000*30*10*10*3*20=180.000.000 bytes or close to 180M. But when I run that program, Task Manager showed me the program took only 3MB (in Mem Usage column). When I started to fill data into my_arr, Mem Usage increased very quickly and program terminated abnormally. Does anyone explain me about that situation? I used VC6 and MFC. Thanks for reading.By
my_struct my_arr[1000][30][10][10][3];
you are allocating memory in the stack, and I don't think the OS will allow your application to allocate that much(180MB) stack memory, so definitely it was going to be terminated abnormally. What I don't understand is why it did not crash right away... Yeah, I too hope some gurus explain it. -
By
my_struct my_arr[1000][30][10][10][3];
you are allocating memory in the stack, and I don't think the OS will allow your application to allocate that much(180MB) stack memory, so definitely it was going to be terminated abnormally. What I don't understand is why it did not crash right away... Yeah, I too hope some gurus explain it.How many are limitation of stack memory!? And if we need huge memory in global, how can we do it?
-
How many are limitation of stack memory!? And if we need huge memory in global, how can we do it?
-
How many are limitation of stack memory!? And if we need huge memory in global, how can we do it?
-
How many are limitation of stack memory!? I think the stack memory usage per process vary throughout OS's but 180MB is unlikely possible.
And if we need huge memory in global, how can we do it?
uh?...You will of course have to allocate them from the heap.but i heard in windows platform, every process can access up tp 4 GB of memeory. (2^32) ???? I want to change Myself..Can u help me? :)
-
I have written a program, in which, I declared a global variable such as:
typedef struct{ char buff[20]; } my_struct; my_struct my_arr[1000][30][10][10][3];
In particular: the size of my_struct is 20 bytes. My calculation showed that the size of my_arr variable is: 1000*30*10*10*3*20=180.000.000 bytes or close to 180M. But when I run that program, Task Manager showed me the program took only 3MB (in Mem Usage column). When I started to fill data into my_arr, Mem Usage increased very quickly and program terminated abnormally. Does anyone explain me about that situation? I used VC6 and MFC. Thanks for reading.Assuming 'global' means that
my_arr
is declared outside any function then the stack doesn't come into it. What's happening is that the executable is being marked as needing more than 180M of memory and this much is reserved in the virtual address space of the process, but until you write (or read....) that memory it isn't actually allocated for real, in some cases you will never be able to have it all as real memory at once, it will be paged in and out from the pagefile as required. This is transparent apart from the slowness. Anyway look at the 'VM Size' column in Task Manager (View->Select Columns, if necessary) I think you will find this shows a more likely amount. I cannot explain why your program terminated abnormally unless you incorrectly accessed the array or your pagefile isn't big enough. Perhaps you could extract a small sample of the code you're using to access the array? I suspect you have an error in parameter order to that unwieldy array and are writing off the end. Anyway the following code runs to completion and you end up with a 'mem usage' of 180M.typedef struct{
char buff[20];
} my_struct;
my_struct my_arr[1000][30][10][10][3];int main()
{
for ( int a = 0; a < 1000; ++a )
for ( int b = 0; b < 30; ++b )
for ( int c = 0; c < 10; ++c )
for ( int d = 0; d < 10; ++d )
for ( int e = 0; e < 3; ++e )
{
my_arr [ a ][ b ][ c ][ d ][ e ].buff [ 0 ] = '0' ;
my_arr [ a ][ b ][ c ][ d ][ e ].buff [ 19 ] = '9' ;
}
return 0;
}Paul
-
but i heard in windows platform, every process can access up tp 4 GB of memeory. (2^32) ???? I want to change Myself..Can u help me? :)
-
but i heard in windows platform, every process can access up tp 4 GB of memeory. (2^32) ???? I want to change Myself..Can u help me? :)
renjith_sree wrote: but i heard in windows platform, every process can access up tp 4 GB of memeory. (2^32) ???? I doubt its 4 gb, windows reserves 2gb kernel and 2gb for user applications.
God is Real, unless declared Integer.