- 论坛徽章:
- 11
|
此言差矣,sgi stl对小于128字节的小内存是有很高效的内存池算法的。
malloc 的效率低是公认了的 ...
ydfgic 发表于 2011-08-26 13:09 ![]()
malloc 的效率是谁公认低了?
sgi stl 内存池自然有其优点, 但毛病也不小
1。 无法处理大块内存申请吧, 如果处理大块内存申请, 要么内存块的跨度必须大, 就是浪费内存; 要么要求链表数量足够多, 如果链表数量足够多, 循环又要多了(分配2, 结果该链表没有, 去4的里面找, 也没有, 去6的链表找, 再没有。。。。)
2。 无法内存回收吧, 除非它再加上buddy 系统, 可是至少sgi stl 没有; 它就是一个动态平衡算法, 适应的峰值不高的应用, 如果一瞬间要求2G的内存, 然后剩下的1个月, 只要求1M的内存, 它的表现不咋地
* Why use this malloc?
0042
0043
This is not the fastest, most space-conserving, most portable, or
0044
most tunable malloc ever written. However it is among the fastest
0045
while also being among the most space-conserving, portable and tunable.
0046
Consistent balance across these factors results in a good general-purpose
0047
allocator for malloc-intensive programs.
0048
0049
The main properties of the algorithms are:
0050
* For large (>= 512 bytes) requests, it is a pure best-fit allocator,
0051
with ties normally decided via FIFO (i.e. least recently used).
0052
* For small (<= 64 bytes by default) requests, it is a caching
0053
allocator, that maintains pools of quickly recycled chunks. 这个是不是sgi stl 的基本手法???
0054
* In between, and for combinations of large and small requests, it does
0055
the best it can trying to meet both goals at once.
0056
* For very large requests (>= 128KB by default), it relies on system
0057
memory mapping facilities, if supported.
0058 |
|