diff --git a/src/util.h b/src/util.h index d41255bd32cc81..ef36bedf57c070 100644 --- a/src/util.h +++ b/src/util.h @@ -487,6 +487,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` for data allocated with `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