我使用下一个结构来存储来自 /proc//maps 的信息:
typedef struct
{
unsigned long vm_start;
unsigned long vm_end;
unsigned long vm_flags;
unsigned long vm_pgoff;
dev_t vm_dev;
unsigned long vm_ino;
unsigned long vm_size;
int vm_shares;
} map_t;
还有一个向量:
typedef struct
{
map_t *arr;
int size;
int reserved;
} map_vector_t;
当我从文件中读取记录时,我找到了一个共享的等效区域:
int index = mem_mapping_find_shared(vector, map);
if (index != -1) {
vector->arr[index].vm_shares++;
continue;
}
map.vm_shares = 0;
int mem_mapping_find_shared(map_vector_t *vector, map_t map)
{
int index = -1;
for (int i = 0; index == -1 && i < vector->size; i++) {
if (mem_mapping_is_shareable(vector->arr[i], map)) {
index = i;
}
}
return index;
}
但它的代码太慢了。我想我应该使用哈希表,对吧?我可以使用哪个哈希函数?