-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
src: malloced_unique_ptr & make_malloced_unique #23642
Conversation
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.
The crypto
changes are not improving the code.
There’s value in grouping all information about a buffer in a single struct
in terms of readability, maintaining less individual local variables if they would otherwise only make sense as a pair.
IMHO they are only loosely make sense as a pair. They are not used as a pair, and are used in association only in: The cost of pairing them together should be weight against using a non-optimal abstraction to store them together. |
They define the bounds of array together. Semantically, they are a pair.
I’m not sure what you mean by “in association” – they are used together in multiple calls you are modifying here. As for the |
13b0bbf
to
a583814
Compare
Yes, but as I read it they are not used together, so the cost of keeping them together outweighs the benefits.
Yeah it's tricky. But I do agree that if that existed it would make sense to use a Buffer-like structure all along. |
It’s better than
What cost are you referring to? There’s zero runtime overhead over having two separate variables, but on the other hand, there’s readability overhead in splitting the struct up. |
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.
I'd rather we document that MallocedBuffer(T* data, size_t size)
assumes that data data was allocated with malloc than delete the method.
a583814
to
5bd49eb
Compare
Reverted unrelated changes, PTAL. |
Alternative to #23641
malloced_unique_ptr
is just a specialization ofstd:unique_ptr
usingfree
for deletion, andmake_malloced_unique<T>
is it's factory usingMalloc<T>
.Ref: #23641
Ref: #23543 (review)
Ref: #23434
CI: https://ci.nodejs.org/job/node-test-pull-request/17822/
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes