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

Re: Sv: Sv: Sv: Memory allocators






>Serious again - any idea on how we can detect whether new throws bad_alloc
>or returns 0 ?

You could try something like the program below. I think you should probably
assume
that a NULL is returned on failure. Last time I checked I think linux
returned a null when
memory ran out. Windows definitely returns a null. There might be macros
for autoconf
that detect it. On the topic of autoconf. Is it possible to run autoconf in
windows? It would
be nice to have something to generate the config.h rather than doing it
manually.

----

#include <iostream>

int main()
   {

   using namespace std;

   try
      {
      char* x;
      while (1)
         {
         x = new char [1048576];
         if (x == 0)
            {
            cout << "NULL returned on memory failure" << endl;
            break;
            }
         }
      }
   catch (...)
      {
      cout << "Exception caught" << endl;
      }
   return 0;
   }