Skip to content

add an initialize method to Heap #2

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

Merged
merged 1 commit into from
Nov 19, 2016
Merged

add an initialize method to Heap #2

merged 1 commit into from
Nov 19, 2016

Conversation

japaric
Copy link

@japaric japaric commented Nov 19, 2016

this lets you create an allocator that doesn't depend on lazy_init.
Example below:

static HEAP: Mutex<Heap> = Mutex::new(Heap::new());

unsafe fn before_main() {
    HEAP.lock().init(BOTTOM, SIZE);
}

fn main() {
    // Use the allocator
}

this lets you create an allocator that doesn't depend on lazy_init.
Example below:

``` rust
static HEAP: Mutex<Heap> = Mutex::new(Heap::new());

unsafe fn before_main() {
    HEAP.lock().init(BOTTOM, SIZE);
}

fn main() {
    // Use the allocator
}
```
pub unsafe fn init(&mut self, heap_bottom: usize, heap_size: usize) {
self.bottom = heap_bottom;
self.size = heap_size;
self.holes = HoleList::new(heap_bottom, heap_size);
Copy link

Choose a reason for hiding this comment

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

wouldn't it be cleaner to simply say *self = Self::new(heap_bottom, heap_size); ?

Copy link
Author

Choose a reason for hiding this comment

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

It would be shorter, yeah. Want me to change it?

Copy link

Choose a reason for hiding this comment

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

doesn't really matter :) once clippy has a lint to lint that it will get fixed :P

@phil-opp phil-opp merged commit 8aa1f64 into rust-osdev:master Nov 19, 2016
@japaric japaric deleted the init branch November 19, 2016 15:49
@phil-opp
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants