Codeforces и Polygon могут быть недоступны в период с 6 декабря, 22:00 (МСК) по 7 декабря, 00:00 (МСК) в связи с проведением технических работ. ×

Memory allocation using Malloc?

Правка en1, от 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.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский ghost_9 2024-12-03 18:24:01 489 Initial revision (published)