История изменений
Исправление hateyoufeel, (текущая версия) :
~/dev> cat alloc.cc
int main()
{
int* LargeArray = new int[262144000000];
LargeArray[262143999999] = 115;
return 0;
}
~/dev> clang++ alloc.cc -o alloc
~/dev> ./alloc
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
zsh: abort ./alloc
~/dev> sudo sysctl vm/overcommit_memory
vm.overcommit_memory = 0
~/dev> sudo sysctl vm/overcommit_memory=1
vm.overcommit_memory = 1
~/dev> ./alloc
~/dev>
Q.E.D.
Исходная версия hateyoufeel, :
~/dev> cat alloc.cc
int main()
{
int* LargeArray = new int[262144000000];
LargeArray[262143999999] = 115;
return 0;
}
~/dev> clang++ alloc.cc -o alloc
~/dev> ./alloc
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
zsh: abort ./alloc
Q.E.D.