coyorkdow opened a new issue, #2430:
URL: https://github.com/apache/brpc/issues/2430

   **Is your feature request related to a problem? (你需要的功能是否与某个问题有关?)**
   
`IOBuf`是brpc通用的buffer类型,它被设计为可以兼容多种可能的底层数据形式。比如`append_user_data`接口可以将用户的一段数据拼接到`IOBuf`中而不产生任何拷贝。
   
   但是这个接口仍然存在局限性。因为它接受的delete仅为`void(void*)`类型,这导致deleter无法保存任何状态或者上下文。
   
   
设想用户使用了一种自定义的内存资源,比如c++17的pmr或者自己实现的arena。用户一次性申请了大块内存,然后将该内存块线性分配给不同的请求,当内存块耗尽时再一次性释放。`std::pmr::monotonic_buffer_resource`的使用就可能存在这样的行为。
   
   
然而由于deleter无法携带状态或者上下文,因此程序无法感知到何时内存资源可以被释放。因为我们无法在deleter中通知资源的持有者,最后一个在该内存资源上的引用已经被释放,现在可以回收内存了。
   
   **Describe the solution you'd like (描述你期望的解决方法)**
   
   将`UserDataDeleter`的类型更换为`std::function<void(void*)>`。
   
   
该方法几乎不会存在overhead。因为`std::function`实现了小对象优化,函数指针会被保存在本地而不是动态开辟额外的内存。可能会导致编译器无法内联deleter,但是这样的影响应该是可以接受的。而换来的是更强的对自定义内存资源的支持,能兼容一些激进的优化。
   
   **Describe alternatives you've considered (描述你想到的折衷方案)**
   
   
   **Additional context/screenshots (更多上下文/截图)**
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to