我们使用一个自定义分配器来清零内存。没什么大不了的。它具有std::allocator中描述的类型和成员函数。
我最近将自定义分配器用于std::vector<T, A>
(带A
分配器),这是自定义分配器的新应用。它在 AIX、BSD、Linux、OSX 和 Windows 上测试正常。
在 Solaris 上进行测试导致编译失败。看起来 SunCC 需要一个size_type max_size(size_type) const
成员函数:
//
// /opt/developerstudio12.5/lib/compilers/include/CC/Cstd/memory
//
size_type max_size () const
{
return alloc_.max_size(sizeof(_Tt));
}
从同一个文件中,有一个size_type max_size (size_type) const
:
//
// Alternate allocator uses an interface class (allocator_interface)
// to get type safety.
//
template <class _Tt>
class allocator
{
public:
...
size_type max_size (size_type size) const
{
return 1 > UINT_MAX/size ? size_type(1) : size_type(UINT_MAX/size);
}
};
在搜索有关 Sun 分配器的信息时,我没有找到有用的结果。
我的第一个问题是,这个成员函数是从哪里来的?它是 SunCC 特有的吗?它是早期 Rogue Wave 实施的遗迹吗?或者也许是别的什么?
我的第二个问题是,是否应该只为 SunCC 添加这个成员函数?或者我们应该使用一个选项来禁用它以实现可移植性?或者也许是别的什么?
以下是 Sun Studio 12.3 和 12.4 的编译结果:
$ CXX=/opt/solarisstudio12.3/bin/CC gmake xed25519.o
/opt/solarisstudio12.3/bin/CC -DNDEBUG -g -xO3 -DCRYPTOPP_DISABLE_AVX2 -template=no%extdef -c xed25519.cpp
"/opt/solarisstudio12.3/prod/include/CC/Cstd/memory", line 479: Error: Too many arguments in call to "CryptoPP::AllocatorBase<unsigned char>::max_size() const".
"/opt/solarisstudio12.3/prod/include/CC/Cstd/vector", line 387: Where: While instantiating "std::allocator_interface<CryptoPP::AllocatorWithCleanup<unsigned char, 0>, unsigned char>::max_size() const".
"/opt/solarisstudio12.3/prod/include/CC/Cstd/vector", line 387: Where: Instantiated from std::vector<unsigned char, CryptoPP::AllocatorWithCleanup<unsigned char, 0>>::max_size() const.
"/opt/solarisstudio12.3/prod/include/CC/Cstd/vector", line 397: Where: Instantiated from non-template code.
1 Error(s) detected.
以下是 Sun Studio 12.5 和 12.6 的编译结果:
$ CXX=/opt/developerstudio12.6/bin/CC gmake xed25519.o
/opt/developerstudio12.6/bin/CC -DNDEBUG -g -xO3 -template=no%extdef -c xed25519.cpp
"/opt/developerstudio12.6/lib/compilers/include/CC/Cstd/memory", line 479: Error: Too many arguments in call to "CryptoPP::AllocatorBase<unsigned char>::max_size() const".
"/opt/developerstudio12.6/lib/compilers/include/CC/Cstd/vector", line 387: Where: While instantiating "std::allocator_interface<CryptoPP::AllocatorWithCleanup<unsigned char, 0>, unsigned char>::max_size() const".
"/opt/developerstudio12.6/lib/compilers/include/CC/Cstd/vector", line 387: Where: Instantiated from std::vector<unsigned char, CryptoPP::AllocatorWithCleanup<unsigned char, 0>>::reserve(unsigned).
"xed25519.h", line 280: Where: Instantiated from non-template code.
>> Assertion: (../lnk/v2vtable.cc, line 49)
while processing xed25519.cpp at line 0.
gmake: *** [xed25519.o] Error 2