ehds commented on issue #2416:
URL: https://github.com/apache/brpc/issues/2416#issuecomment-1774058494

   > 没开-faligned-new还用new来动态分配__attribute__((aligned()))标记的类, 真是aligned了个寂寞
   > 
   
   
   是的,这里还有另外一个隐含的问题。
   如果 brpc 作为第三方库,编译时未加 -faligned-new, 但项目中使用了其头文件中的声明的某个类(cache line 
alignment),并且项目编译使用了 aligned_new, 而该类的析构函数(在 brpc 三方库中定义)的 delete 对象时也不会调用
   ```c++
   void operator delete  ( void* ptr, std::size_t sz,  std::align_val_t al ) 
noexcept;
   ```
   
   也就是说 new (aligned_new) 和 delete 不匹配,delete 的 size 可能会小于实际 new 的 size 
(为类对齐要求的 padding)。
   这里可能会产生一些问题, 例如一些项目中覆盖了 malloc/free,new/delete 定制化了 allocator,会导致申请和释放的大小不一致。


-- 
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