From e3e8c08b01f848543b0f33b0ac6c10a07ff06682 Mon Sep 17 00:00:00 2001 From: David Wells Date: Sun, 31 May 2015 18:11:39 -0400 Subject: [PATCH] Improve the TecplotFlags memory estimate. --- include/deal.II/base/data_out_base.h | 3 +-- include/deal.II/base/memory_consumption.h | 23 +++++++++++++++++++++++ source/base/data_out_base.cc | 6 +++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/include/deal.II/base/data_out_base.h b/include/deal.II/base/data_out_base.h index 4db9987812..6f3d3c5137 100644 --- a/include/deal.II/base/data_out_base.h +++ b/include/deal.II/base/data_out_base.h @@ -910,8 +910,7 @@ namespace DataOutBase /** * Return an estimate for the memory consumption, in bytes, of this - * object. This is not exact (but will usually be close) because calculating - * the memory usage of trees (e.g., std::map) is difficult. + * object. */ std::size_t memory_consumption () const; }; diff --git a/include/deal.II/base/memory_consumption.h b/include/deal.II/base/memory_consumption.h index 1185c11b97..166d03f32b 100644 --- a/include/deal.II/base/memory_consumption.h +++ b/include/deal.II/base/memory_consumption.h @@ -170,6 +170,14 @@ namespace MemoryConsumption inline std::size_t memory_consumption (const long double); + /** + * Determine the amount of memory consumed by a C-style string. The returned + * value does not include the size of the pointer. This function only measures + * up to (and including) the NUL byte; the underlying buffer may be larger. + */ + inline + std::size_t memory_consumption (const char *string); + /** * Determine the amount of memory in bytes consumed by a * std::complex variable. @@ -441,6 +449,21 @@ namespace MemoryConsumption + inline + std::size_t memory_consumption (const char *string) + { + if (string == NULL) + { + return 0; + } + else + { + return /*Don't forget about the NUL! :]*/ sizeof(char) + strlen(string); + } + } + + + template inline std::size_t memory_consumption (const std::complex &) diff --git a/source/base/data_out_base.cc b/source/base/data_out_base.cc index b7622f90fd..880cda09c4 100644 --- a/source/base/data_out_base.cc +++ b/source/base/data_out_base.cc @@ -2306,9 +2306,9 @@ namespace DataOutBase std::size_t TecplotFlags::memory_consumption () const { - // only simple data elements, so - // use sizeof operator - return sizeof (*this); + return sizeof(*this) + + MemoryConsumption::memory_consumption(tecplot_binary_file_name) + + MemoryConsumption::memory_consumption(zone_name); } -- 2.39.5