functionUsingAndInternallyDeletingRowPointer (functionUsingAndInternallyDeletingRowPointer)
And what exactly would this function do? (而这个功能到底会做什么?) Because that memory was allocated by calling std::allocator_traits<std::allocator<T>>::allocate
, which expects it to be deleted by calling std::allocator_traits<std::allocator<T>>::deallocate
. (因为该内存是通过调用std::allocator_traits<std::allocator<T>>::allocate
,所以它期望通过调用std::allocator_traits<std::allocator<T>>::deallocate
来删除它。) Furthermore, each element of the vector
was constructed with a call to std::allocator_traits<std::allocator<T>>::construct
, and therefore must be destroyed by a call to std::allocator_traits<std::allocator<T>>::destroy
. (此外, vector
每个元素都是通过调用std::allocator_traits<std::allocator<T>>::construct
,因此必须通过调用std::allocator_traits<std::allocator<T>>::destroy
来销毁。 std::allocator_traits<std::allocator<T>>::destroy
。)
If that function tries to do delete []
on that pointer, it won't work. (如果该函数试图对该指针执行delete []
,则它将无法正常工作。) Or at the very least, it isn't required to work. (或至少不需要工作。)
It might be reasonable to be able to extract a memory buffer from a vector
and use it directly. (能够从vector
提取内存缓冲区并直接使用它可能是合理的。) But it could not be a mere pointer. (但这不能仅仅是一个指针。) It would have to have an allocator along with it. (它必须具有一个分配器。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…