Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
两者free(NULL)都::operator delete(NULL)允许。分配器概念(例如 std::allocator 是否也允许deallocate(NULL,1),或者是否需要自己保护它?
free(NULL)
::operator delete(NULL)
deallocate(NULL,1)
您需要添加自己的支票。
根据 §20.4.1.1/8,deallocate要求:
deallocate
p 应该是从 allocate() 获得的指针值。n 应等于作为第一个参数传递给返回 p 的 allocate 调用的值。
allocate无法提供存储时引发异常(§20.4.1.1/7)。换句话说,allocate永远不会返回 0,因此deallocate永远不应该得到 0。传递 0 会导致未定义的行为。
allocate