C++17,<memory> 标准库中弃用的函数?
C++17, deprecated functions in <memory> standard library?
我刚刚意识到 Dynamic memory management standard library have been deprecated in C++17. An example is get_temporary_buffer:
的一些功能
template< class T >
std::pair< T*, std::ptrdiff_t > get_temporary_buffer( std::ptrdiff_t count );
谁能解释一下为什么?我可以期望在 C++20 中有替代方案吗?
根据the proposal that deprecates it:
This API would be considered an incomplete thought were it proposed today. As a functional API it lacks exception safety if the function allocating the buffer leaks, yet we offer no RAII-like wrappers to promote safe use.
It has been suggested that all current implementation of this API actually do not perform a more efficient allocation than the regular new
operator, and, if that is genuinely the case, we should seriously consider deprecating this facility. Otherwise, we should probably complete the design with an appropriate guard/wrapper class, and encourage vendors to deliver on missed optimization opportunities.
总之就是用new
/delete
。或者你自己的临时内存分配器;以最适合您的需求为准。
我刚刚意识到 Dynamic memory management standard library have been deprecated in C++17. An example is get_temporary_buffer:
的一些功能template< class T >
std::pair< T*, std::ptrdiff_t > get_temporary_buffer( std::ptrdiff_t count );
谁能解释一下为什么?我可以期望在 C++20 中有替代方案吗?
根据the proposal that deprecates it:
This API would be considered an incomplete thought were it proposed today. As a functional API it lacks exception safety if the function allocating the buffer leaks, yet we offer no RAII-like wrappers to promote safe use.
It has been suggested that all current implementation of this API actually do not perform a more efficient allocation than the regular
new
operator, and, if that is genuinely the case, we should seriously consider deprecating this facility. Otherwise, we should probably complete the design with an appropriate guard/wrapper class, and encourage vendors to deliver on missed optimization opportunities.
总之就是用new
/delete
。或者你自己的临时内存分配器;以最适合您的需求为准。