From 5bd49ebc4fe05dabc338297722912be8ccad5dde Mon Sep 17 00:00:00 2001 From: Refael Ackermann Date: Sat, 13 Oct 2018 12:58:46 -0400 Subject: [PATCH] src: malloced_unique_ptr & make_malloced_unique Ref: https://github.com/nodejs/node/pull/23641 Ref: https://github.com/nodejs/node/pull/23543#pullrequestreview-164467022 Ref: https://github.com/nodejs/node/pull/23434 --- src/util.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/util.h b/src/util.h index 880408df4d57fd..305049853590a8 100644 --- a/src/util.h +++ b/src/util.h @@ -492,6 +492,22 @@ template inline v8::MaybeLocal ToV8Value(v8::Local context, const std::unordered_map& map); +// Helper for `malloced_unique_ptr` +template +struct MallocDeleter { + void operator()(T* ptr) const { free(ptr); } +}; + +// Specialization of `std::unique_ptr` that used `Malloc` +template +using malloced_unique_ptr = std::unique_ptr>; + +// Factory of `malloced_unique_ptr` +template +malloced_unique_ptr make_malloced_unique(size_t number_of_t) { + return malloced_unique_ptr(Malloc(number_of_t)); +} + } // namespace node #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS