Skip to content

Conversation

@dreamos82
Copy link
Member

No description provided.

![The heap status after the merge](/Images/heap_example_after_merge.png)
The fields in bold are the fields that are changed. The exact implementation of this code is left to the reader.
The fields in bold are the fields that are changed. The exact implementation of this code is left to the reader. Please note that some books refers to this technique, calling it _coalescing_, but is the same concepts.
Copy link
Contributor

Choose a reason for hiding this comment

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

You should just introduce it as coalescing in the first place. It is already standard terminology in undergraduate curricula. So maybe early on, we could ask the question: what are some things we want to do with (free) heap blocks? The two natural answers are:

  1. Splitting -> motivate with an example
  2. Coalescing -> motivate with an example
    The examples should show that splitting and coalescing go hand in hand. Imagine you only split, then your block sizes will be non-increasing, which means harder chance to repurpose free blocks. This is why coalescing is helpful.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just reread the whole paragraph, and the main thing is that the approach is basicall incremental, so the "coalesce" concept is only introduced by consecutive examples expanding the previous implementation, and i haven´t found a better place of where to introduce that name earlier. I'll try anyway to rephrase the paragraph.


This is one of the most misleading and subtle issue we can face while osdeving. And most of the time we face it the hard way.

So what is the problem? let's imagine we have a 64 bit variable, and we need some to do a bitwise operation like `setting` the bit at the position `x`, this is easily achieved using the _left shift_ (`|=`) operator combined with a _xor_ (`|=`), like in the following pseudocode:
Copy link
Member

Choose a reason for hiding this comment

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

or, not xor (^=)

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.

4 participants