- 論壇徽章:
- 11
|
此言差矣,sgi stl對(duì)小于128字節(jié)的小內(nèi)存是有很高效的內(nèi)存池算法的。
malloc 的效率低是公認(rèn)了的 ...
ydfgic 發(fā)表于 2011-08-26 13:09 ![]()
malloc 的效率是誰(shuí)公認(rèn)低了?
sgi stl 內(nèi)存池自然有其優(yōu)點(diǎn), 但毛病也不小
1。 無(wú)法處理大塊內(nèi)存申請(qǐng)吧, 如果處理大塊內(nèi)存申請(qǐng), 要么內(nèi)存塊的跨度必須大, 就是浪費(fèi)內(nèi)存; 要么要求鏈表數(shù)量足夠多, 如果鏈表數(shù)量足夠多, 循環(huán)又要多了(分配2, 結(jié)果該鏈表沒(méi)有, 去4的里面找, 也沒(méi)有, 去6的鏈表找, 再?zèng)]有。。。。)
2。 無(wú)法內(nèi)存回收吧, 除非它再加上buddy 系統(tǒng), 可是至少sgi stl 沒(méi)有; 它就是一個(gè)動(dòng)態(tài)平衡算法, 適應(yīng)的峰值不高的應(yīng)用, 如果一瞬間要求2G的內(nèi)存, 然后剩下的1個(gè)月, 只要求1M的內(nèi)存, 它的表現(xiàn)不咋地
* 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. 這個(gè)是不是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 |
|