免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1121 | 回复: 1
打印 上一主题 下一主题

请问struct idr有何作用? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-11-28 12:54 |只看该作者 |倒序浏览
/**
* idr_remove - remove the given id and free it's slot
* idp: idr handle
* id: uniqueue key
*/
void idr_remove(struct idr *idp, int id)
{
        struct idr_layer *p;

        /* Mask off upper bits we don't use for the search. */
        id &= MAX_ID_MASK;

        sub_remove(idp, (idp->layers - 1) * IDR_BITS, id);
        if (idp->top && idp->top->count == 1 && (idp->layers > 1) &&
            idp->top->ary[0]) {  // We can drop a layer

                p = idp->top->ary[0];
                idp->top->bitmap = idp->top->count = 0;
                free_layer(idp, idp->top);
                idp->top = p;
                --idp->layers;
        }
        while (idp->id_free_cnt >= IDR_FREE_MAX) {
                p = alloc_layer(idp);
                kmem_cache_free(idr_layer_cache, p);
                return;
        }
}

注,idr被做成一个根树.
下面是相关注释

* Small id to pointer translation service.
*
* It uses a radix tree like structure as a sparse array indexed
* by the id to obtain the pointer.  The bitmap makes allocating
* a new id quick.
*
* You call it to allocate an id (an int) an associate with that id a
* pointer or what ever, we treat it as a (void *).  You can pass this
* id to a user for him to pass back at a later time.  You then pass
* that id to this code and it returns your pointer.

* You can release ids at any time. When all ids are released, most of
* the memory is returned (we keep IDR_FREE_MAX) in a local pool so we
* don't need to go to the memory "store" during an id allocate, just
* so you don't need to be too concerned about locking and conflicts
* with the slab allocator.
*/


我的疑问是关于struct idr结构的一些基本功能是什么,为何引入struct idr.了解的DX能不能简单解释一下.谢谢!

论坛徽章:
0
2 [报告]
发表于 2006-11-28 12:58 |只看该作者

赫赫,写完好象有点明白了,

这里idr是否是ID RADIX缩写,就是说将ID组织到了一棵RADIX树中.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP