Allocating memory about 10GB on heap

5

I want to allocate about 10 GB on RAM. But I get the error:

error C2148: total size of array must not exceed 0x7fffffff

my simplified code is:

int main(){
    char* myBuffer = new char[11000000000];
    //char* myBuffer = new char[4000000000]; //compiled successfully
}

I know about differences between x86 and x64 and addressing size limit in x86. So I set my target to x64. I also know about stack size limit, but please note that I am allocating on heap.

It is suprising that when I use the below code and it is compiled successfully.

#include <memory>
int main(){
    char* myBuffer = (char*) malloc(11000000000); //compiled successfully even much more than this size
}

What is wrong with my code when I use new operator?

The Environment: Visual studio 2013 using an empty project, Windows server 2008 R2 Datacenter, 128 GB RAM.

Edit: The link provided by n.m. doesn't answer my question completely. I also want to know why does malloc work well but not new?

c++
new-operator
heap-memory
asked on Stack Overflow Sep 26, 2017 by GntS • edited Sep 27, 2017 by GntS

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0