http://stackoverflow.com/questions/11781724/do-i-really-have-to-worry-about-alignment-when-using-placement-new-operator
縮成 https://goo.gl/GYsFKF
也許是我閱讀障礙
我試著理解他的英文但我看不太懂
一開始他貼
18.6.1.3 Placement forms [new.delete.placement]
說這函數被保留 <== 什麼函數 void* operator new(吃size跟void*) 嗎?
C++ program 不應該有函數取代這個 (但就我理解不是可以overload operator new?)
The provisions of (3.7.4) include that the returned pointer should be
suitably aligned, so it's fine for void* operator new (std::size_t size,
void* ptr) noexcept to return a nonaligned pointer if one is passed in. This
doesn't let you off the hook
這段整個看不懂, provisions of (3.7.4) 這是什麼? 然後他講的聽起來是
你overload後 return出一個ptr+1 byte 不aligned的也沒關係.
然後第二塊黃色的又看起來說assumed要aligned.
然後突然一個結論
So if you pass unaligned storage to a placement-new expression you're
violating the assumption that the storage is aligned, and the result is UB.
說不能unaligned.....
完全無法理解整個解答
在這邊請教一下各位
是不是只有我看不太懂, 還是我必須要有什麼background才能
謝謝˙
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 180.218.202.250
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1488470780.A.828.html
藉此標題延伸問一個問題~