64,637
社区成员
发帖
与我相关
我的任务
分享
union obj {
union obj* free_list_link;
char client_data[1];
};
static obj* volatile free_list[16];
int main()
{
alloc* ptr = new alloc; //sgi stl的内存配置器
int sum = 0;
char* cptr1 = (char* )ptr->allocate(16); //分配内存
for (int i = 0; i < __NFREELISTS; i++)
if (ptr->free_list[i] != 0) //大小为16对应free_list[1]
{
alloc::obj* p = ptr->free_list[i];
while(p->free_list_link != NULL)
{
sum++;
cout << p << endl;
p = p->free_list_link;
}
cout << sum << endl;
}
return 0;
}