I'm writing a pool, so its alignment would be type's alignment, which is get from template argument and is not a literal. As C++11's alignas
keyword is still not supported by VS2013, I wrote some macro for this:
#define MY_ALIGNOF(x) __builtin_alignof(x)
#define MY_ALN(x) __declspec(align(x))
template<typename T, int BlockSize>
class MyPool
{
MY_ALN(MY_ALIGNOF(T)) struct MyBlock
{
std::int8_t data[sizeof(T) * BlockSize];
// aligned heap allocators
};
};
Similar approach works for GCC via __alignof__()
and __attribute__((aligned()))
. However, When I use the above things in VS2013, it claims:
error C2059: syntax error : '__builtin_alignof'
So it seems MSVC alignment specifier don't support using non-literal stuff in declspec? Is there any way to specify alignment via another type's alignment?
Aucun commentaire:
Enregistrer un commentaire