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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 ?

There is the sample code here :

//g++ -Wall -o Foo Foo.cpp

#include <cstdio>

class Foo
{
public:
  Foo() : m_val(42) {}
private:
  int m_buffer[0x100 - 1];
  int m_val;
};

int main(int argc, char **argv)
{

  // Test 1
  try
    {
      unsigned nb_foo = 0x400000 - 1;
      Foo *tab = new Foo [nb_foo];
      delete [] tab;
    }
  catch(...)
    {
      fprintf(stderr, "Exception : OK\n");
    }

  // Test 2
  try
    {
      unsigned nb_foo = 0x400000;
      Foo *tab = new Foo [nb_foo];
      delete [] tab;
    }
  catch(...)
    {
      fprintf(stderr, "Exception : OK\n");
    }

  return 0;
}



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux