-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stream_base: use MallocedBuffer abstraction for buffers #23543
Conversation
Drop `Free` and `std::unique_ptr` in favor of Node's `MallocedBuffer` for `char[]` buffer memory mangement.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO in this case std::unique_ptr
is a better abstraction then MallocedBuffer
.
As I see it, since MallocedBuffer
does not use a std::unique_ptr
, it's best for RAII of memory that is taken from an outside API, and when size
should be tracked as well.
What makes this distinction noticeable to me is the continued use of data_size
instead of storage.size
Suggesting a possible tweak, something like: Template<typename T>
struct Free {
void operator()(unique_ptr<T, Deleter>::pointer ptr) const { free(ptr); }
};
Template<typename T>
std::unique_ptr<T, Free<T>> make_malloced_unique(size_t size) {
return std::unique_ptr<T, Free<T>>(Malloc<T>(size));
} |
@refack We have
Why would it be better? It’s just as good as
Yes, because they can be different. |
P.S. and probably most important to me - readability. |
Not sure what changes I need to make here? If @refack’s review stands, then I should probably close the PR. However, as someone new to the project and not the most experienced C++ developer, I find the MallocedBuffer implementation to be much more readable, and I think I reduces the chances of someone like me introducing a memory leak. |
Hello @codyhazelwood and thank you for the contribution. P.S. CI is as green as it's going to get for the time being. |
Drop `Free` and `std::unique_ptr` in favor of Node's `MallocedBuffer` for `char[]` buffer memory mangement. PR-URL: nodejs#23543 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Drop `Free` and `std::unique_ptr` in favor of Node's `MallocedBuffer` for `char[]` buffer memory mangement. PR-URL: nodejs#23543 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Landed in 810c0d9 🎉 @codyhazelwood congratulations on your commit to Node.js! |
Drop `Free` and `std::unique_ptr` in favor of Node's `MallocedBuffer` for `char[]` buffer memory mangement. PR-URL: #23543 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Drop `Free` and `std::unique_ptr` in favor of Node's `MallocedBuffer` for `char[]` buffer memory mangement. PR-URL: #23543 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Drop `Free` and `std::unique_ptr` in favor of Node's `MallocedBuffer` for `char[]` buffer memory mangement. PR-URL: #23543 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Drop `Free` and `std::unique_ptr` in favor of Node's `MallocedBuffer` for `char[]` buffer memory mangement. PR-URL: #23543 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Drop `Free` and `std::unique_ptr` in favor of Node's `MallocedBuffer` for `char[]` buffer memory mangement. PR-URL: #23543 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Franziska Hinkelmann <[email protected]>
Drop
Free
andstd::unique_ptr
in favor of Node'sMallocedBuffer
for
char[]
buffer memory mangement.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes