简体   繁体   中英

C++17, deprecated functions in <memory> standard library?

I am just realizing that some functions of the 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 );

Can somebody explain why? Can I expect there to be an alternative in C++20?

According to 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.

In short, just use new / delete . Or your own temporary memory allocator; whichever works best for your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM