From a1f2dd6c4d3146cb4f84e2a54f6cd5248cdb8203 Mon Sep 17 00:00:00 2001 From: Bram Veenboer Date: Tue, 2 Sep 2025 16:26:27 +0200 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Wiebe van Breukelen --- benchmarks/benchmark_utils.hpp | 7 +++++++ include/trigdx/interface.hpp | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/benchmarks/benchmark_utils.hpp b/benchmarks/benchmark_utils.hpp index 5c9e3ab..6098cbe 100644 --- a/benchmarks/benchmark_utils.hpp +++ b/benchmarks/benchmark_utils.hpp @@ -57,6 +57,10 @@ static void benchmark_cosf(benchmark::State &state) { reinterpret_cast(backend.allocate_memory(N * sizeof(float))); float *c = reinterpret_cast(backend.allocate_memory(N * sizeof(float))); + + if (!x || !c) { + throw std::runtime_error("Buffer allocation failed"); + } auto end = std::chrono::high_resolution_clock::now(); state.counters["init_ms"] = std::chrono::duration_cast(end - start) @@ -91,6 +95,9 @@ static void benchmark_sincosf(benchmark::State &state) { reinterpret_cast(backend.allocate_memory(N * sizeof(float))); float *c = reinterpret_cast(backend.allocate_memory(N * sizeof(float))); + if (!x || !s || !c) { + throw std::runtime_error("Buffer allocation failed"); + } auto end = std::chrono::high_resolution_clock::now(); state.counters["init_ms"] = std::chrono::duration_cast(end - start) diff --git a/include/trigdx/interface.hpp b/include/trigdx/interface.hpp index bbc61ea..b75fed9 100644 --- a/include/trigdx/interface.hpp +++ b/include/trigdx/interface.hpp @@ -12,10 +12,10 @@ public: virtual void init(size_t n = 0) {} virtual void *allocate_memory(size_t bytes) const { - return std::malloc(bytes); + return static_cast(new uint8_t[bytes]); }; - virtual void free_memory(void *ptr) const { std::free(ptr); }; + virtual void free_memory(void *ptr) const { delete[] ptr; }; // Compute sine for n elements virtual void compute_sinf(size_t n, const float *x, float *s) const = 0;