Skip to content

Conversation

@paddyhoran
Copy link
Contributor

No description provided.

@github-actions
Copy link

@paddyhoran
Copy link
Contributor Author

The CI failures are unrelated. @Marwes @jturner314 are you happy with this solution?

Copy link

@jturner314 jturner314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the addition of a null pointer check (see the comment), this looks good to me. I think zeroing out all new memory, as in this PR, is the safest option. My understanding is that zeroing memory is very fast. At some later point, it may be worth revisiting this to see how much of a performance impact it has. (For example, it may be sufficient to just zero out the padding used for SIMD, instead of the entire allocation.) But, without a more thorough review of accesses into memory buffers, I'd prioritize safety over potential performance gains.

);
if new_size > old_size {
std::ptr::write_bytes(
new_ptr.offset(old_size as isize),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fwiw, using the add method is equivalent and a bit more concise:

Suggested change
new_ptr.offset(old_size as isize),
new_ptr.add(old_size),

new_size,
)
);
if new_size > old_size {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be an additional check here in case realloc returns a null pointer (indicating an error), since otherwise the offset will be out-of-bounds. (Also, std::ptr::write_bytes requires the pointer to be non-null.)

Suggested change
if new_size > old_size {
if !new_ptr.is_null() && new_size > old_size {

)
);
if new_size > old_size {
std::ptr::write_bytes(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fwiw, using the .write_bytes() method on the pointer would be a bit more concise.

@paddyhoran
Copy link
Contributor Author

I addressed all the comments. @jturner314 thank you very much for all your time and help!

I'd prioritize safety over potential performance gains.

Yea, definitely my thinking too.

@paddyhoran
Copy link
Contributor Author

@andygrove, @nevi-me @sunchao can I get at least one approval from another committer to get this merged if you have a chance?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants