小编Oll*_*erg的帖子

在C ++中用std :: allocator :: allocate(0)分配零个对象

new int[0]在C ++中是允许的,但是std::allocator<int>().allocate(0)定义明确?更笼统地说,所有分配器都必须接受0作为分配参数吗?

编辑:阅读我测试了Visual Studio的答案后std::allocatorallocate(0)nullptr

deallocate(nullptr, anything) 是点头。

因此,使用nullptr是一个很好的建议,但是标准不要求deallocate(nullptr, 0)是nop,请参见是否允许使用C ++ allocator :: deallocate(NULL,1)?

c++ memory-management allocator dynamic-memory-allocation language-lawyer

5
推荐指数
1
解决办法
127
查看次数