Malloc算法

1, splay tree
http://www.codeproject.com/Articles/14525/Heap-Manager-for-Allocating-Memory-from-a-Shared-M
有两个树LENGTH_TREE 和 POINTER_TREE

2. dlmalloc
http://g.oswego.edu/dl/html/malloc.html
这是个很出名的实现,据说glibc就是基于它的实现。 它把类似大小的组成bin以便改进速度和降低总体的fragmentation

对于小于256byte的请求,使用了一个简单的两倍best fit分配器。如果在当前bin里面没有free blocks,就会将下一个bin分成两半

对于256byte以上但是小于mmap要求的,dlmalloc使用了一个in-place的bitwise trie算法。如果没有足够的空闲空间,dlmalloc会通过system call增大heap大小

For requests above the mmap threshold (a "largebin" request), the memory is always allocated using the mmap system call. The threshold is usually 256 KB.[11] The mmap method averts problems with huge buffers trapping a small allocation at the end after their expiration, but always allocates an entire page of memory, which on many architectures is 4096 bytes in size.[12]
对于大于mmap的请求( "largebin" 请求),内存总是使用mmap实现。这个threshold一般是256kb

3. wiki上列出了常见的一些实现
http://en.wikipedia.org/wiki/C_dynamic_memory_allocation

4. tcmalloc (Thread-caching malloc )
Every thread has local storage for small allocations. For large allocations mmap or sbrk can be used. TCMalloc, a malloc developed by Google,[15] has garbage-collection for local storage of dead threads. The TCMalloc is considered to be more than twice as fast as glibc's ptmalloc for multithreaded programs.[16][17]

5.支持gc的allocator (for c)

http://www.hpl.hp.com/personal/Hans_Boehm/gc/

 

Powered by Jekyll and Theme by solid

本站总访问量