linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* malloc problem to allocate very large blocks
@ 2003-07-28  6:44 Tung-Han Hsieh
  2003-07-28  8:37 ` jw schultz
  2003-07-29  4:58 ` Nagendra Singh Tomar
  0 siblings, 2 replies; 6+ messages in thread
From: Tung-Han Hsieh @ 2003-07-28  6:44 UTC (permalink / raw)
  To: linux-kernel; +Cc: jamagallon

Hello,

I am developing applications which requires more than 2GB memory.
But I found that in my Linux system the malloc() cannot allocate
more than 2GB memory. Here is the details of my system:

CPU:    Pentium 4 2.53 GHz
RAM:    2 GB
Swap:   512 MB
OS:	Debian-3.0 stable
Kernel: 2.4.20
gcc:	2.95.4 20011002
glibc:  2.2.5-6

In theory, in a 32-bits machine the maximum allocatable memory
is up to 4GB. But in the following very simple testing program:

=====================================================================
#include <stdio.h>
#include <stdlib.h>

main()
{
    size_t l;
    char *s1=NULL, *s2=NULL;

    l = 1024*1024*1024;

    s1 = malloc(l);
    s2 = malloc(l);
    if (! s1) printf("s1 malloc failed\n");
    if (! s2) printf("s2 malloc failed\n");
}
=====================================================================

only the block for s1 can be allocated. Further, if I change the
program to

=====================================================================
#include <stdio.h>
#include <stdlib.h>

main()
{
    size_t l;
    char *s1=NULL;

    l = 2*1024*1024*1024;

    s1 = malloc(l);
    if (! s1) printf("s1 malloc failed\n");
}
=====================================================================

the gcc complier complain to me that "foo.c:9: warning: integer overflow
in expression" during the compilation (I use: "gcc foo.c" to compile it),
and the block for s1 cannot be allocated at all. I am wondering if there
is any way to overcome the 2GB limit.

Thank you very much for your reply in advance.


Best Regards,

T.H.Hsieh

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2003-07-29 11:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-07-28  6:44 malloc problem to allocate very large blocks Tung-Han Hsieh
2003-07-28  8:37 ` jw schultz
2003-07-28  9:14   ` jw schultz
2003-07-29  4:58 ` Nagendra Singh Tomar
2003-07-29  5:02   ` Nagendra Singh Tomar
2003-07-29 11:52   ` Alan Cox

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).