gcc version 4.3.2 (Debian 4.3.2-1.1)
On a 64bit system is it possible to get gcc to malloc more than 2GB, which seems to be the limit?
malloc more than 2GB ?
Moderators: hgm, Rebel, chrisw
-
- Posts: 180
- Joined: Mon Sep 03, 2007 9:15 am
Re: malloc more than 2GB ?
Hello Frank,
it works here with Ubuntu 8.10, gcc 4.3.2.
it works here with Ubuntu 8.10, gcc 4.3.2.
Code: Select all
#include <stdlib.h>
#include <stdio.h>
int main( int argc, char *argv[] )
{
void *p = malloc( 0x100000001LL );
printf( "%p\n", p );
exit( 0 );
}
-
- Posts: 228
- Joined: Sun Mar 12, 2006 3:11 pm
Re: malloc more than 2GB ?
Thanks. It works for me too.
I forgot I was making space for a record each of 12 bytes. How embarrassing.....
I forgot I was making space for a record each of 12 bytes. How embarrassing.....
-
- Posts: 228
- Joined: Sun Mar 12, 2006 3:11 pm
Re: malloc more than 2GB ?
Perhaps not.frankp wrote:Thanks. It works for me too.
I forgot I was making space for a record each of 12 bytes. How embarrassing.....
I have effectively:
num = (memory) / sizeof (recordT);
p = (recordT*) malloc (num * sizeof(recordT));
If memory is >2GB then if fails - NULL returned.
-
- Posts: 1922
- Joined: Thu Mar 09, 2006 12:51 am
- Location: Earth
Re: malloc more than 2GB ?
Is memory a signed int perchance? Then you would be trying to malloc negative memory.frankp wrote:Perhaps not.frankp wrote:Thanks. It works for me too.
I forgot I was making space for a record each of 12 bytes. How embarrassing.....
I have effectively:
num = (memory) / sizeof (recordT);
p = (recordT*) malloc (num * sizeof(recordT));
If memory is >2GB then if fails - NULL returned.
-
- Posts: 228
- Joined: Sun Mar 12, 2006 3:11 pm
Re: malloc more than 2GB ?
No...
I tried num = (3000 * 1000000) / sizeof (recordT), where num is uint64
num = (2000 * 1000000) / sizeof (recordT), follow by the malloc is fine.
I tried num = (3000 * 1000000) / sizeof (recordT), where num is uint64
num = (2000 * 1000000) / sizeof (recordT), follow by the malloc is fine.
-
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: malloc more than 2GB ?
Doesn't seem to be an issue on my linux-64 boxes:frankp wrote:gcc version 4.3.2 (Debian 4.3.2-1.1)
On a 64bit system is it possible to get gcc to malloc more than 2GB, which seems to be the limit?
White(1): hash=8192m
hash table memory = 6144M bytes.
Been running with big hashes in things like CCT for years.
-
- Posts: 1922
- Joined: Thu Mar 09, 2006 12:51 am
- Location: Earth
Re: malloc more than 2GB ?
If you had it exactly as written, it would cause issues. The integer literals are signed ints, so the multiplication gets performed (which overflows the signed int and is thus negative), then the division, and then when the whole thing is casted to an unsigned 64 bit by sign extension. The result is still negative.frankp wrote:No...
I tried num = (3000 * 1000000) / sizeof (recordT), where num is uint64
-
- Posts: 1922
- Joined: Thu Mar 09, 2006 12:51 am
- Location: Earth
Re: malloc more than 2GB ?
Oops, of course, the result is not negative. But the result is sign extended to 64 bits, which gives 2^64-3 billion. I just confirmed this with an actual program...
-
- Posts: 228
- Joined: Sun Mar 12, 2006 3:11 pm
Re: malloc more than 2GB ?
Thanks Zach. I just cast the numbers to unsigned and it works fine.Zach Wegner wrote:Oops, of course, the result is not negative. But the result is sign extended to 64 bits, which gives 2^64-3 billion. I just confirmed this with an actual program...