For this simple test and a Linux box with 4 GB or RAM, 0 bytes of swap and processor in x86_64 mode, I can not allocate more than 1 GB of the array.
A source:
Run:
$ file test test: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV) $ ./test ... 24 25 26 27 28 29 30 terminate called after throwing an instance of 'std::bad_alloc' what(): St9bad_alloc Aborted
There is no ulimit for memory:
virtual memory (kbytes, -v) unlimited data seg size (kbytes, -d) unlimited
Why a mistake?
Glibc - 2.3.4, core - 2.6.9
UPDATE: compiler - gcc4.1
Thanks! The test definitely has an error, 1ull<<i gives me up to 31 (2 GB). This error was unintentional. But the real bad code
for(j=0;j<2;j++) for(i=0;i<25;i++) some_array[j][i] = new int[1<<24];
therefore, in the real code there is no sign overflow.
The size of int is 4 bytes:
$ echo 'main(){return sizeof(int);}'| gcc -xc - && ./a.out; echo $? 4
each request will be equal to 1 <24 * 4 = 1 <26; full memory requires 2 * 25 * (1 <26) 3355443200 bytes + 50 * sizeof (pointer) for some_array + 50 * (size of new [] service data.)
osgx source share