maximum memory which malloc can allocate!

Posted by Vikas on Stack Overflow See other posts from Stack Overflow or by Vikas
Published on 2010-05-09T16:31:46Z Indexed on 2010/05/09 16:38 UTC
Read the original article Hit count: 211

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?

© Stack Overflow or respective owner

Related posts about memory-management

Related posts about malloc