-
Notifications
You must be signed in to change notification settings - Fork 54
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
Memory usage optimization #17
Comments
I don't think this will work. Consider https://os.phil-opp.com/kernel-heap/overview.svg: The size of the unused memory block is completely independent from the size of the used memory block afterwards. Basically, the |
This is only in case there is padding due to alignment requirements isn't it? I'll have to look it up how I solved this issue. |
If you keep track of both used and unused chunks, you can use this approach. However, if you only keep track of unused chunks, there is no way to know where the next unused block begins without storing a pointer. |
Well you don't really care about used chunks, since they're not available. And whenever somebody claims to try to free up a chunk, the allocator gets both the address, and the layout of said chunk, and blindly obliges, creating a new chunk (or extends a previous or next one, if the freed up memory are neighbours another free chunk). This would mean that an incorrect call (freeing up nonclaimed space, or double frees) would create corrupt the heap and cause chaos, but that's already the case, isn't it? |
Yes, it is. Even a deallocate call with a valid address can cause undefined behavior due to use-after-free.
Yes, that's why this crate only keeps unused blocks in the list. I just don't understand how we can remove the pointer in the list nodes. |
Based on the discussion in #16:
I think the pointer in the Hole structure can be removed and calculated on the fly from
(&this as usize) + this.size
.Any reason we are not doing that?
The text was updated successfully, but these errors were encountered: