From f8fc2fadc886647186e2ba9a4d8f345aa3cf9eb5 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 24 Oct 2019 14:19:54 -0600 Subject: [PATCH] Report how much memory was requested when we fail allocating that much. --- include/deal.II/base/exceptions.h | 20 ++++++++++++-------- source/base/utilities.cc | 6 +++--- 2 files changed, 15 insertions(+), 11 deletions(-) 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 } -- 2.39.5