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;