malloc分配方案 [英] Malloc Allocation Schemes

查看:111
本文介绍了malloc分配方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是的,我正在电脑系统课程。
我对各种分配方案的几个问题来实现的malloc。
对于明确列出,如果我使用的是后进先出样栈实现的malloc,究竟是一种具有指向previous释放内存的目的是什么?就像你为什么需要双链表?不会单链表一样好?

Yes, I am taking a Computer systems course. I had a few questions about the various allocation schemes to implement malloc. For explicit lists, if I implement malloc using a LIFO-like stack, what exactly is the purpose of having pointers to previous freed memory? Like why do you need doubly-linked lists? Wouldn't singly linked lists work just as well?

malloc的讲座。
我发现这个链接在网上,你可以看看幻灯片7​​,看看我说的。

Malloc lecture. I found this link online, you can look at slide 7 to see what I'm talking about.

当在隔离列表分配方案来看,这些名单是单向的吗?而且,究竟是什么凝聚机制?例如像,如果4个字被释放,你会第一次尝试,并加入它,当你周围的自由空间插入它放回各自的隔离链表过吗?或者你只是在各自的隔离链表的4字部分将4个字块?

When looking at a segregated list allocation scheme, these lists are uni-directional right? And also, what exactly is the coalescing mechanism? Like for example, if 4 words are freed, would you first try and join it when the free space around you before inserting it back into the respective segregated linked list? Or would you simply insert the 4 word block in the '4 word' section of the respective segregated linked list?

感谢您。

推荐答案

由于释放的块总是有两个房间的指针,为什么不双向链接列表?它简化了的聚结code所以它不具有保持从动指针而遍历列表。它还允许遍历列表中的情况下,任一方向存在对列表的末尾可能接近开始搜索提示。一个不起眼的系统我曾经看着中间,最近发生的活动,其中存放的指针。

Since a freed block always has room for two pointers, why not doubly-link the list? It simplifies the coalescing code so it doesn't have to maintain a trailing pointer while traversing the list. It also allows traversing the list in either direction in case there is a hint for which end of the list might be closer to begin the search. One obscure system I once looked at kept a pointer in the "middle", where the last activity occurred.

在释放块。只有四种可能的情况:

When freeing a block. There are only four possible cases:


  • 的可用块相邻的之后的空闲块。

  • 的可用块相邻的的空闲块。

  • 的可用块之间并邻近之前和之后都空闲块。

  • 空闲块不相邻的空闲块。

  • The free block is adjacent after a free block.
  • The free block is adjacent before a free block.
  • The free block is between and adjacent to both free blocks before and after it.
  • The free block is not adjacent to any free block.

合并相邻空闲块的宗旨是:

The purposes of coalescing adjacent free blocks are:


  • 降低链表的长度

  • 要准确地反映一个空闲块的大小不负担分配器向前看,看看两块相邻

排序空闲块到特定长度的空闲列表经常有优惠,但在大多数实际实现,凝聚是一个优先级,以便为不同的页头()要求大小的块进行不适当地拒绝当有许多不同大小的空闲块。

Sorting a free block into a specific-length freelist often has benefits, but in most practical implementations, coalescing is a priority so that an alloc() request for a different size block isn't inappropriately denied when there are many differently-sized free blocks.

这篇关于malloc分配方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆