avatar
这道设计题怎么做?# JobHunting - 待字闺中
l*n
1
Implement a class with have two basic member functions: memAlloc, memDealloc,
The class uses these two functions to manage 512M memory.
Please consider:
1)How to avoid memory fragment;
2)How to support multi-Thread;
3)How to test it.
avatar
g*e
2
看看OS的书 书里都有
avatar
l*n
3
线程安全方面怎么考虑,哪本os书有讲

【在 g*********e 的大作中提到】
: 看看OS的书 书里都有
avatar
s*u
4
这方面的话,我觉得应该也是等效为 producer-consumer problem吧,就是用lock,然
后最多用个condition variable之类。
设计的话就不妨将memory看成一个char数组。不过如何记录空闲位置我没想好。

【在 l********n 的大作中提到】
: 线程安全方面怎么考虑,哪本os书有讲
avatar
l*n
5
会不会有效率问题

【在 s********u 的大作中提到】
: 这方面的话,我觉得应该也是等效为 producer-consumer problem吧,就是用lock,然
: 后最多用个condition variable之类。
: 设计的话就不妨将memory看成一个char数组。不过如何记录空闲位置我没想好。

avatar
n*e
6
我觉得这个和blockingqueue很像
blockingqueue就是support多thread的put和take
这里的put是memAlloc, memDealloc 是take
avoid memory fragment就用circular buffer
support multi-thread用reentrantlock 和condition
test it 就是用写几个function call,先memAlloc再memDealloc,测试一下就可以了。

memDealloc,

【在 l********n 的大作中提到】
: Implement a class with have two basic member functions: memAlloc, memDealloc,
: The class uses these two functions to manage 512M memory.
: Please consider:
: 1)How to avoid memory fragment;
: 2)How to support multi-Thread;
: 3)How to test it.

avatar
s*u
7
对的,好多题目都是producer-consumer这样,blockingqueue就是最典型的。
不过memAlloc应该是take吧,就是consumer,memDealloc是释放空间的,是producer
请教下,比如要alloc的时候,怎么找空闲的位置,就linear的去找么?然后dealloc的
时候,标记一下这段空间表示清空?

了。

【在 n****e 的大作中提到】
: 我觉得这个和blockingqueue很像
: blockingqueue就是support多thread的put和take
: 这里的put是memAlloc, memDealloc 是take
: avoid memory fragment就用circular buffer
: support multi-thread用reentrantlock 和condition
: test it 就是用写几个function call,先memAlloc再memDealloc,测试一下就可以了。
:
: memDealloc,

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。