c++-内存管理-bitmap_alloctor

博客提及数据用64个bit来表示,这属于信息技术中数据表示相关内容。

 

用64个bit来表示

 

int bitmap_add_index (struct bitmap *bitmap, u_int32_t index) { struct bitmap_block *block; int bit; int offset; int first_bit_set; int i; /* Get bitmap. */ if (! bitmap) return BITMAP_FAILURE; /* Get bitmap block. */ block = bitmap->curr_node; if (! block) return BITMAP_FAILURE; /* This is what will be returned. */ block->first_free_index = 0; /* Index value check. */ if (index > INDEX_VALUE_MAX) return BITMAP_FAILURE; /* Find the location of this index in the bitmap block. */ bit = index % INTEGER_BITS; offset = (index % bitmap->block_size) / INTEGER_BITS; /* When corresponding bit is already 0 (used), something is wrong. */ if (! CHECK_FLAG (block->map[offset], (1 << bit))) return BITMAP_FAILURE; /* Set this index's corresponding bit to 0 (used). */ UNSET_FLAG (block->map[offset], (1 << bit)); /* Update the total free indices counter. */ if (block->total_free_indices > 0) block->total_free_indices--; /* Index in this block runs out. */ if (block->total_free_indices == 0) { SET_FLAG (block->flags, BITMAP_BLOCK_FLAG_USED); bitmap_block_mark_released (bitmap, block); /* Check if current node is set. */ if (bitmap->curr_node) return BITMAP_SUCCESS; /* Allocate a new node and make it current. */ if (bitmap->auto_node_create) { /* Check if any released nodes are available. */ bitmap->curr_node = bitmap_use_released (bitmap); if (! bitmap->curr_node) bitmap->curr_node = bitmap_block_new (bitmap, ++bitmap->last_node, bitmap->min_index, bitmap->max_index); return BITMAP_SUCCESS; } else return BITMAP_REQUEST_NEW_ID; } /* Go through the array of integers, and find the first set bit, which will indicate that this bit's corresponding index is empty. */ for (i = offset; i < bitmap->array_size; i++) { /* Find fist bit call. */ first_bit_set = zffs (block->map[i]); /* Found a bit. Figure out the index number it corresponds to. */ if (first_bit_set) { block->first_free_index = ((bitmap->block_size * block->id) + (i * INTEGER_BITS) + first_bit_set - 1); return BITMAP_SUCCESS; } } return BITMAP_FAILURE; } 解析这段代码
最新发布
11-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值