maximum memory which malloc can allocate!
- by Vikas
I was trying to figure out how much memory I can malloc to maximum extent on my machine
(1 Gb RAM 160 Gb HD Windows platform).
I read that maximum memory malloc can allocate is limited to physical memory.(on heap)
Also when a program exceeds consumption of memory to a certain level, the computer stops working because other applications do not get enough memory that they require.
So to confirm,I wrote a small program in C,
int main(){
int *p;
while(1){
p=(int *)malloc(4);
if(!p)break;
}
}
Hoping that there would be a time when memory allocation will fail and loop will be breaked.
But my computer hanged as It was an infinite loop.
I waited for about an hour and finally I had to forcely shut down my computer.
Some questions:
Does malloc allocate memory from HD also?
What was the reason for above behaviour?
Why didn't loop breaked at any point of time.?
Why wasn't there any allocation failure?