开发者

Dynamic Memory Allocation in C++

开发者 https://www.devze.com 2022-12-10 14:50 出处:网络
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++

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

精彩评论

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