Difference AutoFree::Set and Assign
On 22/06/2018 at 10:01, xxxxxxxx wrote:
Cinema 4D Version: R19
Language(s) : C++ ;
In the past I have only had to use the constructor of an AutoFree. Thus passing the object in the AutoFree constructor.
Now, I need to assign an object and was wondering what the difference would be between
The documentation mentions the same for both.
Does both free an already assigned object when assigning/setting a new object, or should I first free the existing object (after a Release()) and then perform an Assign/Set?
On 25/06/2018 at 10:12, xxxxxxxx wrote:
In fact, Set And Assign are internally the same functions. But we have both for some historical reason.
So is up to use whatever you want.
AutoFree is a smart pointer, based on scope. So they do not free the "old" pointer when the pointer is defined by Set/Assign. So you have to do it yourself by calling Release + Free of the returned pointer.
On 25/06/2018 at 11:31, xxxxxxxx wrote:
I had wished this information to be part of the documentation. As it really wasn't clear what the class does with the "old" pointer.
Am I correct to assume that AutoAlloc, AutoNew, AutoPtr all work the same? You need to release and free the old pointed object before assigning a new one
These will only automatically delete the pointed object when going out of scope.
On 26/06/2018 at 02:45, xxxxxxxx wrote:
Thanks for your feedback, it will be added to the documentation.
And yes your assumption is right.