I want to optimize next method
auto MakeBuffer(size_t size)
{
return std::shared_ptr<uint8_t>{new uint8_t[size], std::default_delete<uint8_t[]>()};
}
As you can see buffer is created in two stages:
In general case we can avoid double allocation by using std::make_shared. But how can I do it for dynamic size buffer? std::allocate_shared isn't a solution (if I understand correctly) as a custom allocator is designed to create only object not a controlling block
Edit. Fixed bug in buffer cleaning
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.