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

    Map with BaseList2D as key [SOLVED]

    SDK Help
    0
    5
    523
    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 23/07/2017 at 02:50, xxxxxxxx wrote:

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

      ---------
      Hello.

      I need to have a map with BaseList2D* as keys. 
      I know that if I'm about to store BaseList2D's somewhere, I have to do it in BaseLink.
      Is there any maxon utility data structure for this case or do I have to create a HashMap<BaseLink, OtherType>.

      It appears that ignoring BaseLink and using directly BaseList2D* as keys is bad 
      since the same pointer probably will be used by Cinema 4D for another object if I delete the previous.

      Thank you for your time !

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

        On 23/07/2017 at 04:45, xxxxxxxx wrote:

        If you create and destroy the map in a single pass, you can
        just use the BaseList2D pointer as the key. Otherwise, I
        recommend using the UUID that you can retrieve with

        FindUniqueID(MAXON_CREATOR_ID)

        I also recommend rebuilding the map that uses BaseList2D*
        keys from that map with a single pass through the document.
        You'd be able to rebuild that map in n*log(m) time (assuming
        you're using a map with log(m) access time). I'm just
        mentioning this because my initial thought was to search
        the whole document for every entry but that would yield a
        time complexity of n*m. 🙂

        Cheers,

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

          On 24/07/2017 at 01:14, xxxxxxxx wrote:

          Thank you NiklasR !

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

            On 24/07/2017 at 02:50, xxxxxxxx wrote:

            I guess, the actual question got already answered.
            I just want to add a few words:
            It is not per se bad to store a pointer to a BaseList2D. For example if you are owner of the pointed entities (i.E. you have full control about their destruction), there speaks nothing against it. The thing is, such a pointer can not easily be verified. And if the pointed entities are under Cinema 4D's control (e.g. object in object manager), the pointer may get stale and point to already free'd memory (if the user deleted an object for example) or even worse to memory already used for other means. Here the BaseLink is much superior and protects you from such mishaps. That's why we usually recommend to use BaseLink instead of pointers.

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

              On 24/07/2017 at 05:14, xxxxxxxx wrote:

              Hello Andreas.

              Originally posted by xxxxxxxx

              And if the pointed entities are under Cinema 4D's control (e.g. object in object manager), the pointer may get stale and point to already free'd memory (if the user deleted an object for example) or even worse to memory already used for other means.

              That was exactly the problem. The pointer was pointing to a different valid object from the hierarchy.

              Thank you again for your time !

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