开发者

Dynamic Memory Allocation in C++

What is the difference betwe开发者_JAVA技巧en the 'delete' and 'dispose' C++ operators with regards to dynamic memory allocation?


delete will free memory dynamically allocated in unmanaged C++
Dispose will force custom object implemented maintenance of disposable objects in managed C++/CLI


There's no dispose operator (or standard function, or anything of that ilk) in standard C++ -- are you thinking of some specific proprietary framework, such as Microsoft's .NET "managed C++"? delete is standard, it's indeed an operator, and must behave like this in any standard conforming implementation -- that's the main difference with operator dispose, and also the main difference with operators unicorn, toothfairy, and santaclaus, which have a lot in common since none of those exists!-) [[Sorry Virginia...!]]


I'm assuming this is related to .NET managed C++ because standard C++ has no sense of "dispose".

Delete will release the memory used to store the object; this memory returns to the heap and can be used for other storage requirements.

Dispose will give the object the chance to release resources it acquired such as file handles, etc. Standard C++ would see this sort of task done in the destructor.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜