Skip to content

Commit

Permalink
Merge pull request #232 from bluescarni/pr/complex
Browse files Browse the repository at this point in the history
Complex class
  • Loading branch information
bluescarni authored May 29, 2020
2 parents eefa801 + 9ddc8a9 commit 9c81368
Show file tree
Hide file tree
Showing 69 changed files with 13,424 additions and 320 deletions.
27 changes: 26 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ option(MPPP_BENCHMARK_BOOST "Build benchmarks against Boost.Multiprecision (effe
mark_as_advanced(MPPP_BENCHMARK_BOOST)
option(MPPP_BENCHMARK_FLINT "Build benchmarks against Flint (effective only if MPPP_BUILD_BENCHMARKS is TRUE, requires FLINT)." OFF)
mark_as_advanced(MPPP_BENCHMARK_FLINT)
option(MPPP_WITH_MPFR "Enable features relying on MPFR (e.g., interoperability with long double)." OFF)
option(MPPP_WITH_MPFR "Enable features relying on MPFR." OFF)
option(MPPP_WITH_ARB "Enable features relying on Arb." OFF)
option(MPPP_WITH_MPC "Enable features relying on MPC." OFF)
option(MPPP_WITH_QUADMATH "Enable features relying on libquadmath (e.g., the real128 type)." OFF)
option(MPPP_TEST_PYBIND11 "Build tests for the pybind11 integration utilities (effective only if MPPP_BUILD_TESTS is TRUE, requires pybind11 and Python).")
mark_as_advanced(MPPP_TEST_PYBIND11)
Expand All @@ -46,6 +47,10 @@ if(MPPP_WITH_ARB AND NOT MPPP_WITH_MPFR)
message(FATAL_ERROR "Arb support requires MPFR, please enable the MPPP_WITH_MPFR build option.")
endif()

if(MPPP_WITH_MPC AND NOT MPPP_WITH_MPFR)
message(FATAL_ERROR "MPC support requires MPFR, please enable the MPPP_WITH_MPFR build option.")
endif()

if(YACMA_COMPILER_IS_MSVC AND MPPP_BUILD_STATIC_LIBRARY)
option(MPPP_BUILD_STATIC_LIBRARY_WITH_DYNAMIC_MSVC_RUNTIME "Link to the dynamic MSVC runtime when building mp++ as a static library." OFF)
mark_as_advanced(MPPP_BUILD_STATIC_LIBRARY_WITH_DYNAMIC_MSVC_RUNTIME)
Expand Down Expand Up @@ -221,6 +226,13 @@ endif()
if(MPPP_WITH_MPFR)
set(MPPP_SRC_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/real.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/src/detail/mpfr_arb_cleanup.cpp"
"${MPPP_SRC_FILES}")
endif()

if(MPPP_WITH_MPC)
set(MPPP_SRC_FILES
"${CMAKE_CURRENT_SOURCE_DIR}/src/complex.cpp"
"${MPPP_SRC_FILES}")
endif()

Expand All @@ -233,6 +245,7 @@ if(YACMA_COMPILER_IS_MSVC)
"${CMAKE_CURRENT_SOURCE_DIR}/include/mp++/mp++.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/mp++/rational.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/mp++/real.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/mp++/complex.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/mp++/real128.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/mp++/complex128.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/mp++/type_name.hpp"
Expand All @@ -243,6 +256,7 @@ if(YACMA_COMPILER_IS_MSVC)
"${CMAKE_CURRENT_SOURCE_DIR}/include/mp++/detail/real_literals.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/mp++/detail/real128_literal.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/mp++/detail/mpfr.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/mp++/detail/mpc.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/mp++/detail/type_traits.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/mp++/detail/utils.hpp"
"${CMAKE_CURRENT_SOURCE_DIR}/include/mp++/detail/visibility.hpp"
Expand Down Expand Up @@ -313,6 +327,13 @@ endif()
# on some platforms (see the comment below).
find_package(mp++_GMP REQUIRED)

# Optional dependency on MPC.
if(MPPP_WITH_MPC)
find_package(mp++_MPC REQUIRED)
target_link_libraries(mp++ PUBLIC mp++::MPC)
set(MPPP_ENABLE_MPC "#define MPPP_WITH_MPC")
endif()

# Optional dependency on MPFR.
if(MPPP_WITH_MPFR)
find_package(mp++_MPFR REQUIRED)
Expand Down Expand Up @@ -369,11 +390,15 @@ set(_MPPP_CONFIG_OPTIONAL_DEPS)
if(MPPP_WITH_MPFR)
set(_MPPP_CONFIG_OPTIONAL_DEPS "${_MPPP_CONFIG_OPTIONAL_DEPS}find_package(mp++_MPFR REQUIRED)\n")
endif()
if(MPPP_WITH_MPC)
set(_MPPP_CONFIG_OPTIONAL_DEPS "${_MPPP_CONFIG_OPTIONAL_DEPS}find_package(mp++_MPC REQUIRED)\n")
endif()
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/mp++-config.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/mp++-config.cmake" @ONLY)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/mp++-config.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findmp++_GMP.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findmp++_MPFR.cmake"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findmp++_MPC.cmake"
DESTINATION "${MPPP_INSTALL_LIBDIR}/cmake/mp++")
install(EXPORT mp++_export NAMESPACE mp++:: DESTINATION "${MPPP_INSTALL_LIBDIR}/cmake/mp++")
# Take care of versioning.
Expand Down
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,45 @@
[![Anaconda-Server Badge](https://img.shields.io/conda/vn/conda-forge/mppp.svg?style=for-the-badge)](https://anaconda.org/conda-forge/mppp)
[![DOI](https://zenodo.org/badge/66504757.svg)](https://doi.org/10.5281/zenodo.1043579)

mp++ is a C++11/14/17/20 library for multiprecision arithmetic, currently
mp++ is a C++11/14/17/20 library for multiprecision arithmetic,
featuring:

* arbitrary-precision integers,
* arbitrary-precision rationals,
* quadruple-precision floats,
* quadruple-precision complex numbers,
* arbitrary-precision floats,
* quadruple-precision floats.
* arbitrary-precision complex numbers.

Design goals include:

* excellent performance for small integer and rational
operands,
* easy embeddability in computer algebra systems and
generic C++ libraries,
* a large collection of arbitrary-precision special functions.
* a large collection of arbitrary-precision special functions,
* an ergonomic API based on modern C++ idioms.

Design non-goals include:

* support for fixed-size wide integrals (i.e., no ``uint512_t``,
try [Boost Multiprecision](https://www.boost.org/doc/libs/1_72_0/libs/multiprecision/doc/html/index.html>)
try [Boost Multiprecision](https://www.boost.org/doc/libs/1_72_0/libs/multiprecision/doc/html/index.html)
instead).

Based on well-known libraries such as [GMP](https://gmplib.org/), [MPFR](https://www.mpfr.org) and others,
mp++ was initially conceived as a [GMP](https://gmplib.org/) wrapper with a special focus on performance with
Built on top of the GNU multiprecision stack ([GMP](https://gmplib.org/),
[MPFR](https://www.mpfr.org), [MPC](http://www.multiprecision.org/mpc/)),
mp++ was initially conceived as a GMP wrapper with special focus on performance with
small operands. In particular, a small buffer optimisation and custom implementations of basic mathematical primitives are
instrumental in achieving a performance increase, with respect to GMP and other integer multiprecision libraries, which can be
substantial (see the [benchmarks](https://bluescarni.github.io/mppp/benchmarks.html) section of the documentation).

Eventually, a multiprecision rational class and two multiprecision floating-point classes were added, and today a secondary objective
of mp++ is to provide a modern, consistent and unified C++ interface to several lower-level multiprecision libraries.
Over time, mp++ has accrued many additional features, including
multiprecision real and complex number types, and an expanding
library of special functions (built in part on top of the excellent
[Arb](http://arblib.org/) library).

mp++ is a spinoff of the [Piranha](https://github.com/bluescarni/piranha) library, released under the
[MPL2](https://www.mozilla.org/en-US/MPL/2.0/FAQ/) license.

If you are using mp++ as part of your research, teaching, or other activities, we would be grateful if you could star
the repository and/or cite our work. The DOI of the latest version and other citation resources are available
at [this link](https://doi.org/10.5281/zenodo.1043579).
Expand Down
16 changes: 8 additions & 8 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,23 @@ install:
- if [%BUILD_TYPE%]==[MSVC15_64] conda update -n base conda
- if [%BUILD_TYPE%]==[MSVC15_64] conda config --add channels conda-forge
- if [%BUILD_TYPE%]==[MSVC15_64] conda config --set channel_priority strict
- if [%BUILD_TYPE%]==[MSVC15_64] conda create --name mppp cmake mpir mpfr pybind11 mpmath python=3.6
- if [%BUILD_TYPE%]==[MSVC15_64] conda create --name mppp cmake mpir mpfr mpc pybind11 mpmath python=3.6
- if [%BUILD_TYPE%]==[MSVC15_64] call activate mppp

- if [%BUILD_TYPE%]==[MSVC17_64] call "C:\\Miniconda36-x64\\Scripts\\activate.bat"
- if [%BUILD_TYPE%]==[MSVC17_64] conda config --set always_yes yes
- if [%BUILD_TYPE%]==[MSVC17_64] conda update -n base conda
- if [%BUILD_TYPE%]==[MSVC17_64] conda config --add channels conda-forge
- if [%BUILD_TYPE%]==[MSVC17_64] conda config --set channel_priority strict
- if [%BUILD_TYPE%]==[MSVC17_64] conda create --name mppp cmake mpir mpfr pybind11 mpmath python=3.6
- if [%BUILD_TYPE%]==[MSVC17_64] conda create --name mppp cmake mpir mpfr mpc pybind11 mpmath python=3.6
- if [%BUILD_TYPE%]==[MSVC17_64] call activate mppp

- if [%BUILD_TYPE%]==[MSVC15_clang_64] call "C:\\Miniconda36-x64\\Scripts\\activate.bat"
- if [%BUILD_TYPE%]==[MSVC15_clang_64] conda config --set always_yes yes
- if [%BUILD_TYPE%]==[MSVC15_clang_64] conda update -n base conda
- if [%BUILD_TYPE%]==[MSVC15_clang_64] conda config --add channels conda-forge
- if [%BUILD_TYPE%]==[MSVC15_clang_64] conda config --set channel_priority strict
- if [%BUILD_TYPE%]==[MSVC15_clang_64] conda create --name mppp cmake ninja mpir mpfr
- if [%BUILD_TYPE%]==[MSVC15_clang_64] conda create --name mppp cmake ninja mpir mpfr mpc
- if [%BUILD_TYPE%]==[MSVC15_clang_64] call activate mppp
- if [%BUILD_TYPE%]==[MSVC15_clang_64] clang-cl -v
- if [%BUILD_TYPE%]==[MSVC15_clang_64] call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
Expand All @@ -63,18 +63,18 @@ build_script:
- mkdir build
- cd build

- if [%BUILD_TYPE%]==[MSVC15_64] cmake .. -G "Visual Studio 14 2015 Win64" -DMPPP_BUILD_TESTS=yes -DMPPP_WITH_MPFR=yes -DMPPP_ENABLE_IPO=yes
- if [%BUILD_TYPE%]==[MSVC15_64] cmake .. -G "Visual Studio 14 2015 Win64" -DMPPP_BUILD_TESTS=yes -DMPPP_WITH_MPFR=yes -DMPPP_WITH_MPC=yes -DMPPP_ENABLE_IPO=yes
- if [%BUILD_TYPE%]==[MSVC15_64] cmake --build . --config Debug
- if [%BUILD_TYPE%]==[MSVC15_64] cmake .. -G "Visual Studio 14 2015 Win64" -DMPPP_BUILD_TESTS=yes -DMPPP_WITH_MPFR=yes -DMPPP_TEST_PYBIND11=yes -DMPPP_ENABLE_IPO=yes
- if [%BUILD_TYPE%]==[MSVC15_64] cmake .. -G "Visual Studio 14 2015 Win64" -DMPPP_BUILD_TESTS=yes -DMPPP_WITH_MPFR=yes -DMPPP_WITH_MPC=yes -DMPPP_TEST_PYBIND11=yes -DMPPP_ENABLE_IPO=yes
- if [%BUILD_TYPE%]==[MSVC15_64] cmake --build . --config Release --target pybind11_test_01

# This build enables Unicode solutions.
- if [%BUILD_TYPE%]==[MSVC17_64] cmake .. -G "Visual Studio 15 2017 Win64" -DMPPP_BUILD_TESTS=yes -DMPPP_WITH_MPFR=yes -DCMAKE_CXX_STANDARD=17 -DMPPP_MSVC_UNICODE=YES -DMPPP_ENABLE_IPO=yes
- if [%BUILD_TYPE%]==[MSVC17_64] cmake .. -G "Visual Studio 15 2017 Win64" -DMPPP_BUILD_TESTS=yes -DMPPP_WITH_MPFR=yes -DMPPP_WITH_MPC=yes -DCMAKE_CXX_STANDARD=17 -DMPPP_MSVC_UNICODE=YES -DMPPP_ENABLE_IPO=yes
- if [%BUILD_TYPE%]==[MSVC17_64] cmake --build . --config Debug
- if [%BUILD_TYPE%]==[MSVC17_64] cmake .. -G "Visual Studio 15 2017 Win64" -DMPPP_BUILD_TESTS=yes -DMPPP_WITH_MPFR=yes -DMPPP_TEST_PYBIND11=yes -DCMAKE_CXX_STANDARD=17 -DMPPP_MSVC_UNICODE=YES -DMPPP_ENABLE_IPO=yes
- if [%BUILD_TYPE%]==[MSVC17_64] cmake .. -G "Visual Studio 15 2017 Win64" -DMPPP_BUILD_TESTS=yes -DMPPP_WITH_MPFR=yes -DMPPP_WITH_MPC=yes -DMPPP_TEST_PYBIND11=yes -DCMAKE_CXX_STANDARD=17 -DMPPP_MSVC_UNICODE=YES -DMPPP_ENABLE_IPO=yes
- if [%BUILD_TYPE%]==[MSVC17_64] cmake --build . --config Release --target pybind11_test_01

- if [%BUILD_TYPE%]==[MSVC15_clang_64] cmake .. -GNinja -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_C_COMPILER=clang-cl -DCMAKE_BUILD_TYPE=Debug -DMPPP_BUILD_TESTS=yes -DMPPP_WITH_MPFR=yes -DMPPP_BUILD_STATIC_LIBRARY=yes -DCMAKE_CXX_STANDARD=17 -DMPPP_ENABLE_IPO=yes
- if [%BUILD_TYPE%]==[MSVC15_clang_64] cmake .. -GNinja -DCMAKE_CXX_COMPILER=clang-cl -DCMAKE_C_COMPILER=clang-cl -DCMAKE_BUILD_TYPE=Debug -DMPPP_BUILD_TESTS=yes -DMPPP_WITH_MPFR=yes -DMPPP_WITH_MPC=yes -DMPPP_BUILD_STATIC_LIBRARY=yes -DCMAKE_CXX_STANDARD=17 -DMPPP_ENABLE_IPO=yes
- if [%BUILD_TYPE%]==[MSVC15_clang_64] cmake --build . -- -v

- if [%BUILD_TYPE%]==[MinGW] if [%PLATFORM%]==[x64] cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-Os -fconcepts" -DMPPP_BUILD_TESTS=YES -DMPPP_WITH_MPFR=YES -DMPPP_WITH_QUADMATH=yes -DMPPP_GMP_INCLUDE_DIR=C:/local/include -DMPPP_GMP_LIBRARY=C:/local/lib/libgmp.a -DMPPP_MPFR_INCLUDE_DIR=C:/local/include -DMPPP_MPFR_LIBRARY=C:/local/lib/libmpfr.a -DMPPP_TEST_NSPLIT=%TEST_NSPLIT% -DMPPP_TEST_SPLIT_NUM=%SPLIT_TEST_NUM% ..
Expand Down
25 changes: 25 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,28 @@ function(ADD_MPPP_BENCHMARK arg1)
add_custom_command(TARGET benchmark POST_BUILD COMMAND "${arg1}" WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
endfunction()

# NOTE: the malloc tracking feature requires glibc.
# Heuristically, let's enable it only Unix systems
# which are not OSX. Even on systems which are Unix
# but don't use glibc, the library should do no harm
# as long as the platform has sane rpath handling.
# NOTE: see also the explanation here:
# https://stackoverflow.com/questions/17803456/an-alternative-for-the-deprecated-malloc-hook-functionality-of-glibc
if(NOT WIN32 AND UNIX AND NOT APPLE)
add_library(track_malloc SHARED track_malloc.cpp)
set_target_properties(track_malloc PROPERTIES CXX_VISIBILITY_PRESET hidden)
set_target_properties(track_malloc PROPERTIES VISIBILITY_INLINES_HIDDEN TRUE)
target_compile_options(track_malloc PRIVATE
"$<$<CONFIG:Debug>:${MPPP_CXX_FLAGS_DEBUG}>"
"$<$<CONFIG:Release>:${MPPP_CXX_FLAGS_RELEASE}>"
"$<$<CONFIG:RelWithDebInfo>:${MPPP_CXX_FLAGS_RELEASE}>"
"$<$<CONFIG:MinSizeRel>:${MPPP_CXX_FLAGS_RELEASE}>"
)
set_property(TARGET track_malloc PROPERTY CXX_STANDARD 11)
set_property(TARGET track_malloc PROPERTY CXX_STANDARD_REQUIRED YES)
set_property(TARGET track_malloc PROPERTY CXX_EXTENSIONS NO)
endif()

ADD_MPPP_BENCHMARK(integer1_dot_product_unsigned)
ADD_MPPP_BENCHMARK(integer2_dot_product_unsigned)
ADD_MPPP_BENCHMARK(integer1_dot_product_signed)
Expand Down Expand Up @@ -82,4 +104,7 @@ ADD_MPPP_BENCHMARK(integer2_uint_conversion)

if(MPPP_WITH_MPFR)
ADD_MPPP_BENCHMARK(real_alloc)
if(NOT WIN32 AND UNIX AND NOT APPLE)
target_link_libraries(real_alloc PRIVATE track_malloc)
endif()
endif()
33 changes: 29 additions & 4 deletions benchmark/real_alloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,46 @@

#include <mp++/real.hpp>

#include "track_malloc.hpp"

using real = mppp::real;
using mpfr_float = boost::multiprecision::mpfr_float;

// An example taken from here:
// https://www.boost.org/doc/libs/1_72_0/libs/multiprecision/doc/html/boost_multiprecision/intro.html#boost_multiprecision.intro.expression_templates
template <typename T>
T test_function(const T &x)
T test_function(const T &x, bool move = false)
{
T a[7] = {T{1.}, T{2.}, T{3.}, T{4.}, T{5.}, T{6.}, T{7.}};

return (((((std::move(a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0];
if (move) {
return (((((std::move(a[6]) * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0];
} else {
return (((((a[6] * x + a[5]) * x + a[4]) * x + a[3]) * x + a[2]) * x + a[1]) * x + a[0];
}
}

int main()
{
return test_function(real{42.}) == 0;
// return test_function(mpfr_float{42.}) == 0;
real arg1{42.};
mpfr_float arg2{42.};

{
mppp_bench::malloc_tracker t{"bmp::mpfr_float"};
test_function(arg2);
}
{
mppp_bench::malloc_tracker t{"mppp::real"};
test_function(arg1);
}
{
mppp_bench::malloc_tracker t{"bmp::mpfr_float + move"};
test_function(arg2, true);
}
{
mppp_bench::malloc_tracker t{"mppp::real + move"};
test_function(arg1, true);
}

return 0;
}
65 changes: 65 additions & 0 deletions benchmark/track_malloc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright 2016-2020 Francesco Biscani ([email protected])
//
// This file is part of the mp++ library.
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#include "track_malloc.hpp"

#if defined(MPPP_HAVE_GLIBC)

#include <atomic>
#include <cstddef>
#include <iostream>

namespace mppp_bench
{

namespace detail
{

namespace
{

// The tracking counter. This will be increased
// each time the malloc() override below is
// invoked.
std::atomic<std::size_t> malloc_counter(0);

} // namespace

} // namespace detail

} // namespace mppp_bench

// NOTE: see here for an explanation:
// https://stackoverflow.com/questions/17803456/an-alternative-for-the-deprecated-malloc-hook-functionality-of-glibc
extern "C" void *__libc_malloc(std::size_t size);

// NOTE: apparently it is not necessary to declare
// this function as visible.
extern "C" void *malloc(std::size_t size)
{
++mppp_bench::detail::malloc_counter;
return ::__libc_malloc(size);
}

namespace mppp_bench
{

malloc_tracker::malloc_tracker(const char *s) : m_name(s), m_count(detail::malloc_counter.load()) {}

malloc_tracker::~malloc_tracker()
{
// NOTE: compute the total number of allocations
// before outputting to stream, so that we avoid
// counting possible allocations from stream operations.
const auto tot_nalloc = detail::malloc_counter.load() - m_count;
std::cout << "Tracker '" << m_name << "' observed " << tot_nalloc << " malloc() calls." << std::endl;
}

} // namespace mppp_bench

#endif
57 changes: 57 additions & 0 deletions benchmark/track_malloc.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright 2016-2020 Francesco Biscani ([email protected])
//
// This file is part of the mp++ library.
//
// This Source Code Form is subject to the terms of the Mozilla
// Public License v. 2.0. If a copy of the MPL was not distributed
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.

#ifndef MPPP_BENCHMARK_TRACK_MALLOC_HPP
#define MPPP_BENCHMARK_TRACK_MALLOC_HPP

// Machinery to check the presence of GLIBC. See:
// https://sourceforge.net/p/predef/wiki/Libraries/
#include <climits>

#if defined(__GNU_LIBRARY__) || defined(__GLIBC__)

#define MPPP_HAVE_GLIBC

#endif

#if defined(MPPP_HAVE_GLIBC)

#include <cstddef>
#include <string>

namespace mppp_bench
{

struct __attribute__((visibility("default"))) malloc_tracker {
explicit malloc_tracker(const char *);
~malloc_tracker();
// NOTE: it is important than m_name
// is inited befor m_count, so that
// we don't end up counting allocations
// from the string.
std::string m_name;
std::size_t m_count;
};

} // namespace mppp_bench

#else

namespace mppp_bench
{

struct malloc_tracker {
explicit malloc_tracker(const char *) {}
~malloc_tracker() {}
};

} // namespace mppp_bench

#endif

#endif
Loading

0 comments on commit 9c81368

Please sign in to comment.