-
Notifications
You must be signed in to change notification settings - Fork 37
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
Avoid memory copy when parsing log #202
Avoid memory copy when parsing log #202
Conversation
@@ -572,7 +572,8 @@ int NuRaftLogSegment::loadLogEntry(int fd, off_t offset, LogEntryHeader * head, | |||
return -1; | |||
} | |||
|
|||
entry = LogEntryBody::parse(entry_str, head->term, head->data_length); | |||
entry = LogEntryBody::parse(entry_str, head->data_length); | |||
entry->set_term(head->term); | |||
|
|||
delete[] entry_str; |
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.
why not use buffer for entry_str instead of char pointer to avoid copy and delete.
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.
Because when we serialize data there is no header of buffer and this copy can not be avoided
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.
Got it, maybe better to use buffer
to avoid manual memory release.
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.
No need to worry about memory deallocation issues for the method is only invoked synchronously.
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.
But I think we should not use raw pointer in NuRaftLogSegment.cpp
, maybe fixed in another PR.
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.
okay
LGTM |
Which issues of this PR fixes:
This PR try to fix #199
Change log: