From: Wolfgang Bangerth Date: Thu, 24 Oct 2019 20:19:54 +0000 (-0600) Subject: Report how much memory was requested when we fail allocating that much. X-Git-Tag: v9.2.0-rc1~942^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F8959%2Fhead;p=dealii.git Report how much memory was requested when we fail allocating that much. --- diff --git a/include/deal.II/base/exceptions.h b/include/deal.II/base/exceptions.h index b95201b618..0833fa83c5 100644 --- a/include/deal.II/base/exceptions.h +++ b/include/deal.II/base/exceptions.h @@ -690,14 +690,18 @@ namespace StandardExceptions /** * Trying to allocate a new object failed due to lack of free memory. */ - DeclExceptionMsg(ExcOutOfMemory, - "Your program tried to allocate some memory but this " - "allocation failed. Typically, this either means that " - "you simply do not have enough memory in your system, " - "or that you are (erroneously) trying to allocate " - "a chunk of memory that is simply beyond all reasonable " - "size, for example because the size of the object has " - "been computed incorrectly."); + DeclException1(ExcOutOfMemory, + std::size_t, + "Your program tried to allocate some memory but this " + "allocation failed. Typically, this either means that " + "you simply do not have enough memory in your system, " + "or that you are (erroneously) trying to allocate " + "a chunk of memory that is simply beyond all reasonable " + "size, for example because the size of the object has " + "been computed incorrectly." + "\n\n" + "In the current case, the request was for " + << arg1 << " bytes."); /** * A memory handler reached a point where all allocated objects should have diff --git a/source/base/utilities.cc b/source/base/utilities.cc index 2ad59b0000..c0dd4e532b 100644 --- a/source/base/utilities.cc +++ b/source/base/utilities.cc @@ -1036,14 +1036,14 @@ namespace Utilities #ifndef DEAL_II_MSVC const int ierr = ::posix_memalign(memptr, alignment, size); - AssertThrow(ierr == 0, ExcOutOfMemory()); - AssertThrow(*memptr != nullptr, ExcOutOfMemory()); + AssertThrow(ierr == 0, ExcOutOfMemory(size)); + AssertThrow(*memptr != nullptr, ExcOutOfMemory(size)); #else // Windows does not appear to have posix_memalign. just use the // regular malloc in that case *memptr = malloc(size); (void)alignment; - AssertThrow(*memptr != 0, ExcOutOfMemory()); + AssertThrow(*memptr != 0, ExcOutOfMemory(size)); #endif }