首頁 / CompScience / Programming / Languages / C_and_CPP / new Expression versus operator new Function

new Expression versus operator new Function

C++ Primer 4/e在Optimizing Memory Allocation這個地方有一個術語:『

The library functions operator new and operator delete are misleadingly named. Unlike other operator functions, such as operator=, these functions do not overload the new or delete expressions. In fact, we cannot redefine the behavior of the new and delete expressions.

A new expression executes by calling an operator new function to obtain memory and then constructs an object in that memory. A delete expression executes by destroying an object and then calls an operator delete function to free the memory used by the object.

警告

Because the new (or delete) expressions and the underlying library functions have the same name, it is easy to confuse the two.』

中文版的這樣寫:『程式庫提供的operator new的函式和operator delete函式,其名稱很容易帶來混淆。不同於其他operator 函式(例如operator=),上述兩函式並沒有對new或delete算式進行重載。事實上我們不能重新定義new算式和delete算式的行為。

new算式的行為包括呼叫operator new函式取得記憶體,然後在該記憶體建構一個物件。delete算式的行為包括銷毀一個物件並呼叫operator delete函式以釋放物件所用的記憶體。

警告

由於new(或delete)算式及其底層所用函式的名稱相同,兩者很容易被混淆。』

Print Friendly, PDF & Email
馬上成為工作達人的Fans

About ㄚ琪

工作達人Fun Taiwan的創辦者及總編,可以在這裡更認識他。

發表迴響

你的電子郵件位址並不會被公開。 Required fields are marked *

*

這個網站採用 Akismet 服務減少垃圾留言。進一步瞭解 Akismet 如何處理網站訪客的留言資料

Scroll To Top