From c2da564ffe5c7db48e067a7a05063ca5435a6fd1 Mon Sep 17 00:00:00 2001 From: Justin Carpentier <justin.carpentier@inria.fr> Date: Mon, 30 Jan 2023 17:08:55 +0100 Subject: [PATCH] core: add aligned_malloc --- include/eigenpy/alignment.hpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/eigenpy/alignment.hpp b/include/eigenpy/alignment.hpp index b04a7d63..bb888b8d 100644 --- a/include/eigenpy/alignment.hpp +++ b/include/eigenpy/alignment.hpp @@ -29,6 +29,18 @@ struct aligned_instance { typename aligned_storage<sizeof(Data)>::type storage; }; +inline void *aligned_malloc( + std::size_t size, std::size_t alignment = EIGENPY_DEFAULT_ALIGN_BYTES) { + void *original = std::malloc(size + alignment); + if (original == 0) return 0; + void *aligned = + reinterpret_cast<void *>((reinterpret_cast<std::size_t>(original) & + ~(std::size_t(alignment - 1))) + + alignment); + *(reinterpret_cast<void **>(aligned) - 1) = original; + return aligned; +} + } // namespace eigenpy namespace boost { -- GitLab