Allocate more than 2 GB on the heap using C ++ on the 32-bit Linux kernel

This seems to be a very common problem, but I have not yet found a specific answer.

I have access to a server that runs linux, has 16 GB of RAM and a 16-core (64-bit) processor (/ proc / cpuinfo gives "Intel (R) Xeon (R) CPU E5520 @ 2.27GHz"). However, the kernel is 32bit (uname -m gives i686). Of course, I don’t have root access, so I can’t change that.

I am running C ++ - a program that I wrote that does some hungry calculations, so I need a big heap - but whenever I try to allocate more than 2 GB, I get badalloc, although ulimit returns "unlimited". For simplicity, let me say that my program is as follows:

#include <iostream>
#include <vector>

int main() {
    int i = 0;
    std::vector<std::vector<int> > vv;
    for (;;) {
        ++i;
        vv.resize(vv.size() + 1);
        std::vector<int>* v = &(vv.at(vv.size() - 1));
        v->resize(1024 * 1024 * 128);
        std::cout << i * 512 << " MB.\n";
    }
    return 0;
}

After compiling with g ++ (without flags) the output is:

512 MB.
1024 MB.
1536 MB.
2048 MB.
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc
Aborted

, 32- , -, , 32- 2 ^ 32 ( , , 64- , , 2 ?)

, , , , , .

, : - ? , , , , ..... 2 , , , .

"", .

, Lukas

+5
2

, , , 64- ​​( , )

, , .

, , , , . - , . .

, , 64- , , .

EDIT: 2 , , , . , root-.

+5

- "". , . , , , .

, , 2 , , , 4 . , " ".

.

, 64- .

0

All Articles