-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
stream_base: use MallocedBuffer abstraction for buffers #23543
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
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 <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
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 <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
|
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 <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Drop `Free` and `std::unique_ptr` in favor of Node's `MallocedBuffer` for `char[]` buffer memory mangement. PR-URL: #23543 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Drop `Free` and `std::unique_ptr` in favor of Node's `MallocedBuffer` for `char[]` buffer memory mangement. PR-URL: #23543 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Drop `Free` and `std::unique_ptr` in favor of Node's `MallocedBuffer` for `char[]` buffer memory mangement. PR-URL: #23543 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Drop `Free` and `std::unique_ptr` in favor of Node's `MallocedBuffer` for `char[]` buffer memory mangement. PR-URL: #23543 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
Drop
Freeandstd::unique_ptrin favor of Node'sMallocedBufferfor
char[]buffer memory mangement.Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes