Why is the size of StaticVector<float, 3> is 16 bytes, not 12?
Issue #189
resolved
#define BLAZE_USE_PADDING 0
#include "blaze/Blaze.h"
typedef float vec3_t[3];
int main() {
blaze::StaticVector<float, 3> vec1;
vec3_t vec2;
printf("vec1: %d bytes, vec2: %d bytes\n", sizeof(vec1), sizeof(vec2));
}
Result: vec1: 16 bytes, vec2: 12 bytes
Comments (5)
-
-
-
assigned issue to
-
assigned issue to
-
- changed status to open
-
- changed status to resolved
Commit 5c7a55c reworks the alignment evaluation of the
StaticVector
class template. Commits 9c852e6, 635fdab, and 8a11e27 do the same for theHybridVector
,StaticMatrix
, andHybridMatrix
class templates, respectively. The fix is immediately available via cloning the Blaze repository and will be officially released in Blaze 3.4. -
Hi Віталій!
In Blaze 3.7 we’ve extended the interface for
StaticVector
andStaticMatrix
(see issue#134). With this feature you’ll be able to explicitly specify whether you need alignment and/or padding. This will give you full control over the size of aStaticVector
andStaticMatrix
instance. Hopefully this is useful for you,Best regards,
Klaus!
- Log in to comment
Hi Віталій!
Thanks for raising this issue. The reason that a
StaticVector<float,3>
requires 16 bytes instead of 12 is because vectorization is still turned on. Vectorization requires an alignment of 16 bytes for SSE or even 32 bytes for AVX (we assume SSE for the following discussion). Sincefloat
is a vectorizable data type aStaticVector<float,3>
is subject to these alignment restrictions and the size is padded to the next multiple of 16.In case padding is turned off it is no longer possible to use a
StaticVector<float,3>
in vectorized operations. Hence it is reasonable to assume that the alignment restrictions are lifted and its size is reduced to 12. However, unintuitively aStaticVector<float,5>
would be subject to the restrictions and would require 32 bytes since the first fourfloat
values could be uses for vector instructions.We will discuss the implications of introducing this special case. We apologize for the delay to resolve this issue. Thanks again for raising this issue,
Best regards,
Klaus!