Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Register
    • Login

    Difference AutoFree::Set and Assign

    SDK Help
    0
    4
    762
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      On 22/06/2018 at 10:01, xxxxxxxx wrote:

      User Information:
      Cinema 4D Version:   R19 
      Platform:      
      Language(s) :     C++  ;

      ---------
      Hi,

      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

      AutoFree::Set
      AutoFree::Assign

      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?

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        On 25/06/2018 at 10:12, xxxxxxxx wrote:

        Hi Daniels,

        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.

        Cheers,
        Maxime

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          On 25/06/2018 at 11:31, xxxxxxxx wrote:

          Thanks Maxime,
          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.

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

            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.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post