From 843f1a635683be3374a02ea7c5542d4a6fe3454a Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Sat, 28 May 2016 08:45:43 +0200 Subject: [PATCH] Set LeafNode alignment to LEAF_PAGE_SIZE bytes References: - https://github.com/Project-OSRM/osrm-backend/pull/2348#issuecomment-219804408 - http://stackoverflow.com/questions/15523537/alignas-specifier-vs-attribute-aligned-c11 - http://stackoverflow.com/questions/7895869/cross-platform-alignx-macro --- include/util/static_rtree.hpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/include/util/static_rtree.hpp b/include/util/static_rtree.hpp index 6a0b7e744..f62c5c2db 100644 --- a/include/util/static_rtree.hpp +++ b/include/util/static_rtree.hpp @@ -32,6 +32,16 @@ #include #include +// An extended alignment is implementation-defined, so use compiler attributes +// until alignas(LEAF_PAGE_SIZE) is compiler-independent. +#if defined(_MSC_VER) +#define ALIGNED(x) __declspec(align(x)) +#elif defined(__GNUC__) +#define ALIGNED(x) __attribute__ ((aligned(x))) +#else +#define ALIGNED(x) +#endif + namespace osrm { namespace util @@ -74,13 +84,11 @@ class StaticRTree std::uint32_t children[BRANCHING_FACTOR]; }; - struct LeafNode + struct ALIGNED(LEAF_PAGE_SIZE) LeafNode { LeafNode() : object_count(0), objects() {} std::uint32_t object_count; std::array objects; - unsigned char leaf_page_padding[LEAF_PAGE_SIZE - sizeof(std::uint32_t) - - sizeof(std::array)]; }; static_assert(sizeof(LeafNode) == LEAF_PAGE_SIZE, "LeafNode size does not fit the page size");