Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python 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
    • Login

    Allocating memory

    SDK Help
    0
    2
    356
    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 04/09/2017 at 03:45, xxxxxxxx wrote:

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

      ---------
      Hi Folks,

      looking for some clarification on allocating and deallocating memory.

      When should an ObjectData inherited class destroy its data? Should this be done in the destructor, or should I be overriding Free()? Something else?

      Similar question for the constructor. In my custom classes I set all pointers to nullptr in the constructor, and usually allocate the memory elsewhere (I setup my own initialiser functions). But in my ObjectData plugins I do this in the constructor. Should I be doing this in the Init() function? I read a post here from a few years a go that said the Init() might be called more than once - why might this happen? And should I therefore be setting up tests inside the Init() function?

      WP.

      Edit - spelling error!

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

        On 05/09/2017 at 07:45, xxxxxxxx wrote:

        Hi WP,

        while you technically can use constructor and destructor for such purposes, we strongly recommend not to do so. Rather use Init() and Free(). The reason is the return value of Init(), so other parts of Cinema can react to for example allocation failures and an object not initializing correctly thereof.

        See also the manual on NodeData::Init().

        Init() may indeed be called several times for example for object instances on the undo stack (while not being the exact same instances, they still somewhat refer to the same object). If this causes problems for your implementation you will need to handle this yourself. See also the manual on the Undo System.

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