boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 怎样高效管理内存?
相关主题
哪位在Linux上用C++碰到过memory fragmentation吗?
菜鸟请教C问题
寻找一个allocator 做一个指定内存空间内的 alloc/free
问个问题 (转载)
Dynamic buffer management question
问一个 Andrei A. 的 Modern c++ design 书里边的一个问题
How solid it is: c++/c# call Matlab library
为什么会有recursion stack overflow这个问题?
effective C++里的memory pool 一问:
why do we still use dynamic allocation?
相关话题的讨论汇总
话题: 内存话题: memory话题: allocate话题: pool话题: allocation
进入Programming版参与讨论
1 (共1页)
s********k
发帖数: 6180
1
准备修改vendor提供的内存管理程序(embedded device,heap非常少大概1K-2K)。原
来的程序采用walk through整个heap的方法,遇到free的内存块就比较大小,如果足够
大,存入这块内存,如果不够大,查紧接着下一块内存是否free,如果free的话就
merge,不行的话跳过继续查找。同时内存allocation成功在某个block之后比较剩余的
内存是否过大,过大的话split这个block。因为程序可能会遇到比较多的较小的内存并
且大小不一致,这样的话allocation,free多的话内存hole太多。想问一下这样的情况
一般怎么解决比较好?谢谢
s****n
发帖数: 786
2
google memory bytes pool and memory blocks pool

【在 s********k 的大作中提到】
: 准备修改vendor提供的内存管理程序(embedded device,heap非常少大概1K-2K)。原
: 来的程序采用walk through整个heap的方法,遇到free的内存块就比较大小,如果足够
: 大,存入这块内存,如果不够大,查紧接着下一块内存是否free,如果free的话就
: merge,不行的话跳过继续查找。同时内存allocation成功在某个block之后比较剩余的
: 内存是否过大,过大的话split这个block。因为程序可能会遇到比较多的较小的内存并
: 且大小不一致,这样的话allocation,free多的话内存hole太多。想问一下这样的情况
: 一般怎么解决比较好?谢谢

k****f
发帖数: 3794
3
2K的空间,还是简单的管理比较合适吧

【在 s********k 的大作中提到】
: 准备修改vendor提供的内存管理程序(embedded device,heap非常少大概1K-2K)。原
: 来的程序采用walk through整个heap的方法,遇到free的内存块就比较大小,如果足够
: 大,存入这块内存,如果不够大,查紧接着下一块内存是否free,如果free的话就
: merge,不行的话跳过继续查找。同时内存allocation成功在某个block之后比较剩余的
: 内存是否过大,过大的话split这个block。因为程序可能会遇到比较多的较小的内存并
: 且大小不一致,这样的话allocation,free多的话内存hole太多。想问一下这样的情况
: 一般怎么解决比较好?谢谢

s********k
发帖数: 6180
4
比较简单的管理的话,能不能应付内存fragmentation的问题?有什么好的推荐?

【在 k****f 的大作中提到】
: 2K的空间,还是简单的管理比较合适吧
t****t
发帖数: 6806
5
这个多半跟你分配的pattern有关. 可能的话, 一次都分配好了不要释放比较好...

【在 s********k 的大作中提到】
: 比较简单的管理的话,能不能应付内存fragmentation的问题?有什么好的推荐?
s********k
发帖数: 6180
6
这太难了,我看前面建议的byte memory是不是就是任意大小,可能会需要
fragmentation以及defrag,然后block memory就是固定的block,更快,没有
fragmentation以及defrag,但是会有浪费(比如需要的内存只占用block的一半)。前
段时间记得版上讨论有说俄罗斯人写了个很高效的malloc类似函数?有人能讲解下高效
在哪里呢?谢谢

【在 t****t 的大作中提到】
: 这个多半跟你分配的pattern有关. 可能的话, 一次都分配好了不要释放比较好...
t****t
发帖数: 6806
7
for example, you know most of your memory chunk is 20 bytes. then you
allocate a chunk of 20*40 bytes as a pool. then whenever you want to
allocate 20 bytes, you allocate from that pool. this kind of pool is quite
easy to maintain as you don't need to know the size of chunk, so there is no
waste.
but again this depends on your allocation pattern. if you allocate a lot of
different size of memory block (say 1, 2, 5, 10, 20, 34, 40, 50, 100, etc),
that obviously is not an option. on the other hand, if you only allocate
several different size of block, say 10, 14, 25, then this is good. without
pattern and given so small memory, any suggestion will be vague.

【在 s********k 的大作中提到】
: 这太难了,我看前面建议的byte memory是不是就是任意大小,可能会需要
: fragmentation以及defrag,然后block memory就是固定的block,更快,没有
: fragmentation以及defrag,但是会有浪费(比如需要的内存只占用block的一半)。前
: 段时间记得版上讨论有说俄罗斯人写了个很高效的malloc类似函数?有人能讲解下高效
: 在哪里呢?谢谢

s********k
发帖数: 6180
8
多谢,那general的RTOS上的memory management一半是block pool和byte pool都用吗
?然后应用程序(开发者)自己选择哪个合适?

no
of
,
without

【在 t****t 的大作中提到】
: for example, you know most of your memory chunk is 20 bytes. then you
: allocate a chunk of 20*40 bytes as a pool. then whenever you want to
: allocate 20 bytes, you allocate from that pool. this kind of pool is quite
: easy to maintain as you don't need to know the size of chunk, so there is no
: waste.
: but again this depends on your allocation pattern. if you allocate a lot of
: different size of memory block (say 1, 2, 5, 10, 20, 34, 40, 50, 100, etc),
: that obviously is not an option. on the other hand, if you only allocate
: several different size of block, say 10, 14, 25, then this is good. without
: pattern and given so small memory, any suggestion will be vague.

a****l
发帖数: 8211
9
for such a small memory device, I don't even think it is a good idea to use
dynamic memory allocation. At least, do not use dynamic memory allocation
extensively, only use it when absolutely necessary and no other solution.
If you followed this direction, you might find that the vendor provided
method is more than good enough.

【在 s********k 的大作中提到】
: 准备修改vendor提供的内存管理程序(embedded device,heap非常少大概1K-2K)。原
: 来的程序采用walk through整个heap的方法,遇到free的内存块就比较大小,如果足够
: 大,存入这块内存,如果不够大,查紧接着下一块内存是否free,如果free的话就
: merge,不行的话跳过继续查找。同时内存allocation成功在某个block之后比较剩余的
: 内存是否过大,过大的话split这个block。因为程序可能会遇到比较多的较小的内存并
: 且大小不一致,这样的话allocation,free多的话内存hole太多。想问一下这样的情况
: 一般怎么解决比较好?谢谢

t****t
发帖数: 6806
10
i have no idea.

【在 s********k 的大作中提到】
: 多谢,那general的RTOS上的memory management一半是block pool和byte pool都用吗
: ?然后应用程序(开发者)自己选择哪个合适?
:
: no
: of
: ,
: without

r********3
发帖数: 2998
11
不要动态使用,只允许静态使用。

【在 s********k 的大作中提到】
: 准备修改vendor提供的内存管理程序(embedded device,heap非常少大概1K-2K)。原
: 来的程序采用walk through整个heap的方法,遇到free的内存块就比较大小,如果足够
: 大,存入这块内存,如果不够大,查紧接着下一块内存是否free,如果free的话就
: merge,不行的话跳过继续查找。同时内存allocation成功在某个block之后比较剩余的
: 内存是否过大,过大的话split这个block。因为程序可能会遇到比较多的较小的内存并
: 且大小不一致,这样的话allocation,free多的话内存hole太多。想问一下这样的情况
: 一般怎么解决比较好?谢谢

1 (共1页)
进入Programming版参与讨论
相关主题
why do we still use dynamic allocation?
请教:vector size in R
奇怪的问题:关于一个简单的malloc()小程序 (转载)
How to split sk_buf into 2
一个interview问题,关于内存泄漏
c++的问题
请问C++ exception后如何清理function stack上的内存资源?
C++程序如何处理内存分块?
突然发现现在很反感malloc了
请问释放容器内存的方法
相关话题的讨论汇总
话题: 内存话题: memory话题: allocate话题: pool话题: allocation