Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 925
Picaud Vincent Avatar asked Dec 19 '17 14:12

Picaud Vincent


1 Answers

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.

like image 163
Nicol Bolas Avatar answered Sep 30 '22 02:09

Nicol Bolas