-
Notifications
You must be signed in to change notification settings - Fork 52
Made hole module public for external uses. #47
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
Moved `align_layout()` function into `HoleList`
|
Thanks!
I would prefer to move the |
|
I think that is a good idea. |
|
But |
|
Yes, I would keep them in |
|
Well, done! |
phil-opp
left a comment
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.
Thanks! A few more nits, then this should be ready.
src/hole.rs
Outdated
| /// Searches the list for a big enough hole. A hole is big enough if it can hold an allocation | ||
| /// of `layout.size()` bytes with the given `layout.align()`. If such a hole is found in the | ||
| /// list, a block of the required size is allocated from it. Then the start address of that | ||
| /// block is returned. |
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.
Could you update the docs for the new second return type? For example:
"[...] Then the start address of that block and the aligned layout are returned. The automatic layout alignment is required because the HoleList has some additional layout requirements for each memory block."
src/lib.rs
Outdated
| let res = self.holes.allocate_first_fit(layout); | ||
| if res.is_ok() { | ||
| self.used += aligned_layout.size(); | ||
| self.used += res.unwrap().1.size(); | ||
| } | ||
| res | ||
| res.map(|tuple| tuple.0) |
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.
You could simplify this with a match to avoid the unwrap():
match self.holes.allocate_first_fit(layout) {
Ok((ptr, aligned_layout)) => {
self.used += aligned_layout.size();
Ok(ptr)
}
Err(err) => Err(err),
}|
Done |
phil-opp
left a comment
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.
Thank you!
|
Published as v0.8.10 |
Hi Phil!
I've made hole.rs public for external uses and moved
align_layout()function intoHoleList.Heapstill contains thesizeand theusedcounters, so it is stillHeapthat usesalign_layout.Tell me if this is not the best solution