代码之家  ›  专栏  ›  技术社区  ›  jww avp

SunCC std::分配器和size\u type max\u size(size\u type)const成员函数?

  •  4
  • jww avp  · 技术社区  · 6 年前

    custom allocator 使记忆归零。没什么大不了的。它具有中描述的类型和成员函数 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);
        }
    };
    

    我的第一个问题是,这个成员函数是从哪里来的?是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
    
    0 回复  |  直到 6 年前