Sha256: 50e053d920e906d1af9ce3bb2a7bc70ce7b6d6852f4679e088590d80b33e7efa

Contents?: true

Size: 1.04 KB

Versions: 135

Compression:

Stored size: 1.04 KB

Contents

//#include <list>
#include <stdexcept>
#include <stdio.h>

using namespace std;

struct BigStruct
{
  char _data[4096];
};

void bad_alloc_test()
{
  typedef allocator<BigStruct> BigStructAllocType;
  BigStructAllocType bigStructAlloc;

  try {
    //Lets try to allocate almost 4096 Go (on most of the platforms) of memory:
    BigStructAllocType::pointer pbigStruct = bigStructAlloc.allocate(1024 * 1024 * 1024);

    // CPPUNIT_ASSERT( pbigStruct != 0 && "Allocation failed but no exception thrown" );
  }
  catch (bad_alloc const&) {
    printf( "Ok\n" );
  }
  catch (...) {
    //We shouldn't be there:
    // CPPUNIT_ASSERT( false && "Not bad_alloc exception thrown." );
  }
}

void bad_alloc_test1()
{
  try {
    allocator<BigStruct> all;
    BigStruct *bs = all.allocate(1024*1024*1024);

    // throw bad_alloc();
  }
  catch ( bad_alloc const & ) {
    printf( "I am here\n" );
  }
  catch ( ... ) {
  }
}

int main()
{
  bad_alloc_test();
#if 0
  try {
    throw bad_alloc();
  }
  catch ( bad_alloc& ) {
  }
  catch ( ... ) {
  }
#endif
  return 0;
}

Version data entries

135 entries across 135 versions & 2 rubygems

Version Path
rhodes-7.6.0 platform/shared/stlport/test/compiler/eh.cc
rhodes-7.5.1 platform/shared/stlport/test/compiler/eh.cc
rhodes-7.4.1 platform/shared/stlport/test/compiler/eh.cc
rhodes-7.1.17 platform/shared/stlport/test/compiler/eh.cc
rhodes-6.2.0 platform/shared/stlport/test/compiler/eh.cc
rhodes-6.0.11 platform/shared/stlport/test/compiler/eh.cc
rhodes-5.5.18 platform/shared/stlport/test/compiler/eh.cc
rhodes-5.5.17 platform/shared/stlport/test/compiler/eh.cc
rhodes-5.5.15 platform/shared/stlport/test/compiler/eh.cc
rhodes-5.5.0.22 platform/shared/stlport/test/compiler/eh.cc
rhodes-5.5.2 platform/shared/stlport/test/compiler/eh.cc
rhodes-5.5.0.7 platform/shared/stlport/test/compiler/eh.cc
rhodes-5.5.0.3 platform/shared/stlport/test/compiler/eh.cc
rhodes-5.5.0 platform/shared/stlport/test/compiler/eh.cc
tauplatform-1.0.3 platform/shared/stlport/test/compiler/eh.cc
tauplatform-1.0.2 platform/shared/stlport/test/compiler/eh.cc
tauplatform-1.0.1 platform/shared/stlport/test/compiler/eh.cc
rhodes-3.5.1.12 platform/shared/stlport/test/compiler/eh.cc
rhodes-3.3.5 platform/shared/stlport/test/compiler/eh.cc
rhodes-3.4.2 platform/shared/stlport/test/compiler/eh.cc