How to detect that memory over 4G isn't available ?

Tom Browder tom.browder@gmail.com
Tue Aug 17 13:58:00 GMT 2010


On Mon, Aug 16, 2010 at 12:49, Paul Chavent <paul.chavent@fnac.net> wrote:
> Hi.
>
> I have a class with ctor that initialise members.
> If i instanciate an array of that class that spread on >= 4G i have a
> segfault.
> Is it a bug (kernel, gcc, my app) ?
> What do you suggest for avoiding this please ?

Maybe tou could test the availability of memory.  See man 2 getrlimit:

       #include <sys/time.h>
       #include <sys/resource.h>

       int getrlimit(int resource, struct rlimit *rlim);

           struct rlimit {
               rlim_t rlim_cur;  /* Soft limit */
               rlim_t rlim_max;  /* Hard limit (ceiling for rlim_cur) */
           };

       RLIMIT_AS
              The maximum size of the process's virtual memory
(address space) in bytes.  This limit affects calls to brk(2),
mmap(2)  and  mremap(2),  which
              fail  with  the error ENOMEM upon exceeding this limit.
Also automatic stack expansion will fail (and generate a SIGSEGV that
kills the process
              if no alternate stack has been made available via
sigaltstack(2)).  Since the value is a long, on machines with a 32-bit
long either this  limit
              is at most 2 GiB, or this resource is unlimited.

HTH

-Tom

Thomas M. Browder, Jr.
Niceville, Florida
USA



More information about the Gcc-help mailing list