返回信息流路过,书中没有解释吗?
这是一条镜像帖。来源:北邮人论坛 / cpp / #102185同步于 2022/9/26
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
Re: c++,内存池求助
plazum
2022/9/26镜像同步17 回复
订阅后,新回复会通过你的通知中心匿名送达。
9 条回复
我的理解是本来应该是用一个指针指向当前区块,但他使用了柔性数组,效果应该是一样的
【 在 plazum 的大作中提到: 】
: 书上怎么说的,介绍一下嘛,我也很好奇
注释里写了,第二个字段是 client data:https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/ext/pool_allocator.h#L84-L88
大致看了一下,如果 Obj 在 freelist 里,则用 _M_free_list_link 指向同一个 freelist 里的下一个 Obj,否则 _M_client_data 指向 client 的数据。注意这里是 union。
参考 _M_allocate_chunk 函数的实现:https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/src/c%2B%2B98/pool_allocator.cc#L63
不明觉厉
【 在 Vampire (Vampire) 的大作中提到: 】
: 注释里写了,第二个字段是 client data:https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/include/ext/pool_allocator.h#L84-L88
: 大致看了一下,如果 Obj 在 freelist 里,则用 _M_free_list_link 指向同一个 freelist 里的下一个 Obj,否则 _M_client_data 指向 client 的数据。注意这里是 union。
: 参考 _M_allocate_chunk 函数的实现:https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/src/c++98/pool_allocator.cc#L63
我在repo里搜了一下,整个代码库里都没有对_M_client_data的使用(https://github.com/gcc-mirror/gcc/search?q=_M_client_data),只有对_M_free_list_link的使用(https://github.com/gcc-mirror/gcc/search?q=_M_free_list_link),这是怎么回事呢?
【 在 Vampire 的大作中提到: 】
: 注释里写了,第二个字段是 client data:https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/ext/pool_allocator.h#L84-L88
: 大致看了一下,如果 Obj 在 freelist 里,则用 _M_free_list_link 指向同一个 freelist 里的下一个 Obj,否则 _M_client_data 指向 client 的数据。注意这里是 union。
: 参考 _M_allocate_chunk 函数的实现:https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/src/c%2B%2B98/pool_allocator.cc#L63
因为union关键字,两者不会同时被使用,可以省8个字节
【 在 plazum 的大作中提到: 】
: 我在repo里搜了一下,整个代码库里都没有对_M_client_data的使用(https://github.com/gcc-mirror/gcc/search?q=_M_client_data),只有对_M_free_list_link的使用([url=https://github.com/gcc-mirror/gcc/search?q=_M_free_li
: ............