Codeforces and Polygon may be unavailable from December 6, 19:00 (UTC) to December 6, 21:00 (UTC) due to technical maintenance. ×

Memory allocation using Malloc?

Revision en1, by ghost_9, 2024-12-03 18:24:01
void solve()
{
  int *a = (int*)malloc(1000000000*sizeof(int));//case 1
 
  cout<<1<<endl;
  return;
}

So recently I was asked a question? Why this code compile and does not give RTE, it had to do something with virtual memory if you use a vector array instead it will provide bad_alloc as RTE. So what is the reason behind it or is it compiler dependent?

But the hint was to think about how virtual memory can be used here.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English ghost_9 2024-12-03 18:24:01 489 Initial revision (published)