When trying to determine the size of glm::vec3 (from GLM math library) by using the size of operator like so:
sizeof(glm::vec3)
I get 12 returned. When I look at the definition of a vec3 struct I see this:
template <typename T, precision P = defaultp>
struct tvec3
{
// -- Implementation detail --
typedef tvec3<T, P> type;
typedef tvec3<bool, P> bool_type;
typedef T value_type;
# ifdef GLM_META_PROG_HELPERS
static GLM_RELAXED_CONSTEXPR length_t components = 3;
static GLM_RELAXED_CONSTEXPR precision prec = P;
# endif//GLM_META_PROG_HELPERS
// -- Data --
# if GLM_HAS_ANONYMOUS_UNION
union
{
struct{ T x, y, z; };
struct{ T r, g, b; };
struct{ T s, t, p; };
# ifdef GLM_SWIZZLE
_GLM_SWIZZLE3_2_MEMBERS(T, P, tvec2, x, y, z)
_GLM_SWIZZLE3_2_MEMBERS(T, P, tvec2, r, g, b)
_GLM_SWIZZLE3_2_MEMBERS(T, P, tvec2, s, t, p)
_GLM_SWIZZLE3_3_MEMBERS(T, P, tvec3, x, y, z)
_GLM_SWIZZLE3_3_MEMBERS(T, P, tvec3, r, g, b)
_GLM_SWIZZLE3_3_MEMBERS(T, P, tvec3, s, t, p)
_GLM_SWIZZLE3_4_MEMBERS(T, P, tvec4, x, y, z)
_GLM_SWIZZLE3_4_MEMBERS(T, P, tvec4, r, g, b)
_GLM_SWIZZLE3_4_MEMBERS(T, P, tvec4, s, t, p)
# endif//GLM_SWIZZLE
};
//other code......
}
For which I see three structs, each with three member variables of templated type T, which in GLM defaults to float type. My question is why is the sizeof() operator returning 12 bytes as the size of glm::vec3 when it looks like it should be 36 bytes:
3 structs, with 3 float members each = 3*3*4(number of bytes in a float) = 36.