[webkit-dev] Be careful for using `new builtin[xxx]` / `make_unique<builtin[]>(num)`

Yusuke SUZUKI utatane.tea at gmail.com
Tue Feb 20 07:37:49 PST 2018


Hi WebKittens,

I recently saw several `make_unique<builtin[]>(num)` code.
This is good if we know that we do not extend this array dynamically.
However, be careful for the type of this... Otherwise, we bypass bmalloc
and go to slow system malloc!
For example, `make_unique<char[]>(num)` will allocate buffer from system
malloc.

If you use `std::make_unique<XXX[]>(num)` and XXX uses
WTF_MAKE_FAST_ALLOCATED, it is OK since it has new[]/delete[] operators.

I think one way to alleviate this issue is just using MallocPtr.
Personally, I would like to use make_unique, but it does not accept
allocator for std::unique_ptr<char[], XXX>'s XXX.

Please correct me if I'm wrong.

Best regards,
Yusuke Suzuki
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20180221/7e3bcb42/attachment.html>


More information about the webkit-dev mailing list