Skip to content
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

对heap.c中split_chunk()的疑问。 #5

Closed
SilverRainZ opened this issue Apr 22, 2015 · 2 comments
Closed

对heap.c中split_chunk()的疑问。 #5

SilverRainZ opened this issue Apr 22, 2015 · 2 comments

Comments

@SilverRainZ
Copy link
Contributor

Hi, hurley:

在heap.c中,分割内存块的函数split_chunk(header_t *chunk, uint32_t len),其中len是期望获得的chunk的长度,那么分割出来的newchunk的长度不应该是
newchunk = chunk + len吗?

mm/heap.c line 137 function split_chunk()

if (chunk->length - len > sizeof (header_t)) {
-       header_t *newchunk = (header_t *)((uint32_t)chunk + chunk->length);
+       header_t *newchunk = (header_t *)((uint32_t)chunk + len);
                ... ... 
}

不知道我的想法有没有错,望解答 :)

@hurley25
Copy link
Owner

嗯,看起来是有点问题,你可以提个pull request的。这里的代码来自James的文档,我还真没有写测试。很抱歉对你造成了困扰,现在的hurlex-II使用链表的封装实现这块代码,相对来说可读性好一些:
https://github.com/hurley25/Hurlex-II/blob/master/mm/slob.c

@SilverRainZ
Copy link
Contributor Author

好的,谢谢你的答复以及文档,受益良多。
待会我提个PR。

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

No branches or pull requests

2 participants