Avi*_*vio 4 c++ heap stack memory-management c++11
我想尝试新的Hinnant的short_alloc分配器,据我所知,它取代了旧的stack_alloc分配器.但是,我无法编译矢量示例.g++说:
~# g++ -std=c++11 stack-allocator-test.cpp -o stack-allocator-test
In file included from stack-allocator-test.cpp:6:0:
short_alloc.h:11:13: error: ‘alignment’ is not a type
short_alloc.h:11:22: error: ISO C++ forbids declaration of ‘alignas’ with no type [-fpermissive]
short_alloc.h:11:22: error: expected ‘;’ at end of member declaration
Run Code Online (Sandbox Code Playgroud)
据我所知,g++抱怨line 10和11:
static const std::size_t alignment = 16;
alignas(alignment) char buf_[N];
Run Code Online (Sandbox Code Playgroud)
似乎编译器不喜欢alignas的"表达式版本",但它只需要"type-id版本".
我g++ 4.7.2在Ubuntu 12.10下使用.
~# g++ --version
g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
Run Code Online (Sandbox Code Playgroud)
可能我错过了一些明显的东西,但我无法弄清楚.任何帮助,将不胜感激.(请不要告诉我,我必须升级到更新g++,我懒得这样做:)
g ++ - 4.7.2不支持alignas.来自http://gcc.gnu.org/projects/cxx0x.html:
对齐支持| N2341 | GCC 4.8
尝试使用g ++ - 4.8.0或clang; 或者你可以使用__attribute__((aligned)):
__attribute__((aligned (8))) char buf_[12];
Run Code Online (Sandbox Code Playgroud)
注意,__attribute__((aligned))只接受某些整数常量表达式(文字,模板参数); 它不接受static const变量.