0

In sub-allocation of SGI STL allocator, there are 16 free-lists which separately manage small blocks of size 8,16,....,128. The structure of the free-lists' node is:

union obj{
    union obj *free_list_link;
    char client_data[1];
}

My question is : why it is designed like this? What is the member client_data used for?

4

1 回答 1

1

这是一种常见的设计模式。client_data[] 实际上是 8、16、.. 128 字节。如果您查看分配 obj 的位置,它可能看起来像 malloc( sizeof(obj) + 128 ) 用于 128 字节块。

于 2012-11-30T04:06:19.187 回答