Brent-Campbell
asked on
Overcoming 32MB limit boundary for malloc on Linux
Hi,
Using gcc on RHEL 5.1, I've allocated some memory using malloc (134,217,728) and malloc returns the pointer to the memory successfully, but I always receive a segmentation fault after trying to index after 32MB, I assume there is a 32MB boundary in place.
Is there anyway to increase this limit?
Many thanks.
Using gcc on RHEL 5.1, I've allocated some memory using malloc (134,217,728) and malloc returns the pointer to the memory successfully, but I always receive a segmentation fault after trying to index after 32MB, I assume there is a 32MB boundary in place.
Is there anyway to increase this limit?
Many thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Try the following code to see it if fails. If it doesn't the problem lays somewhere else.
#include <malloc.h>
#include <assert.h>
int main()
{
char * p = malloc(0xFFFFFFF);
assert(p);
p[0xFFFFFFE]=0;
return 0;
}
BTW: I know I forgot the call to free() -- but it's only to test so I'm not too concerned about a memory leak :)
can you show us the code where you allocate the memory and where you access it?
any chance you dont access it through a byte-pointer (unsigned char or char), like:
struct any_big_object { ... };
any_big_object *pobjs = (any_big_object *)malloc(134.217.728);
// this accesses the byte at 32MB (33554432), you have to cast pobjs to char-pointer before adding the offset for it
char i = *((char*)pobjs + 33554432);
// or
char i = ((char*)pobjs)[335544329];
// this accesses the struct at position 335544329, which might fail, because it accesses the byte 335544329*sizeof(any_big_o bject)
char i = *(char*)(pobjs + 33554432);
or
char i = ((char*)pobjs)[33554432];
well, it might be easier if we see your code .. ;)
ike
any chance you dont access it through a byte-pointer (unsigned char or char), like:
struct any_big_object { ... };
any_big_object *pobjs = (any_big_object *)malloc(134.217.728);
// this accesses the byte at 32MB (33554432), you have to cast pobjs to char-pointer before adding the offset for it
char i = *((char*)pobjs + 33554432);
// or
char i = ((char*)pobjs)[335544329];
// this accesses the struct at position 335544329, which might fail, because it accesses the byte 335544329*sizeof(any_big_o
char i = *(char*)(pobjs + 33554432);
or
char i = ((char*)pobjs)[33554432];
well, it might be easier if we see your code .. ;)
ike
ASKER
Many thanks for all of your comments. I've actually discovered this isn't the problem, the problem was actually due to jumping four bytes rather than one in a for loop and therefore accessing unallocated memory!
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Technically, the 2GB limit is correct, yet some other runtime constraints may lower that limit. Take a look at http://www.linuxdevcenter.com/pub/a/linux/2006/11/30/linux-out-of-memory.html ("When Linux Runs Out of Memory") for a more in-depth view.
BTW, to learn more about system limts, check out 'getrlimit()' (http://www.opengroup.org/onlinepubs/009695399/functions/getrlimit.html)
BTW, to learn more about system limts, check out 'getrlimit()' (http://www.opengroup.org/onlinepubs/009695399/functions/getrlimit.html)
Hi Brent-Campbell,
Did you need anymore assistance with this?
-Rx
Did you need anymore assistance with this?
-Rx
ASKER
Sorry for the huge delay, thanks for your time and efforts and realising that the problem was elsewhere!
Open in new window