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
    • Login

    Faster Vector list... how?

    SDK Help
    0
    25
    13.9k
    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 20/04/2015 at 15:54, xxxxxxxx wrote:

      How does one use, say, BaseArray with my_spline->GetPoints()?  Do you simply cast or does one need to copy the Vector* array into the BaseArray?  What exactly?  You guys continue to tout this stuff but where are the extensive usage examples?  Even these types are well hidden in the API docs.  And they are not used in the cinema4dsdk examples.  One reason that I don't use them is there is no exemplification of their usage.

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

        On 20/04/2015 at 16:10, xxxxxxxx wrote:

        Well, that is an excellent question, Robert.
        I would also like to know that.

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

          On 20/04/2015 at 17:02, xxxxxxxx wrote:

          I'd use STL, std::vector can handle all of this, fast, cache friendly, I think I use it 99% of the time.

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

            On 20/04/2015 at 17:16, xxxxxxxx wrote:

            The problem with the STL is that is utilizes Exceptions and the C4D SDK does not.  If an exception is thrown you must be assured to capture and handle all of them or the code will unwind back to C4DMain (and crash).  As the docs say:

            "Do not use external libraries (e.g STL or BOOST) unless absolutely necessary."

            and

            "C++ exceptions and RTTI will not be used in any of our projects unless external libraries require it (also RTTI operators typeid and dynamic_cast cannot be used)."

            You can use them but be aware of the caveats.

            ETA: I see that the "Plugin Code Style Guide" does mention the use of BaseArray et al in a basic sense.  It would be nice to know more about using these classes with the built-in pointer arrays (such as Vector and CPolygon arrays).

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

              On 20/04/2015 at 18:26, xxxxxxxx wrote:

              I think you can compile with exceptions turned off? at least this is doable in visual studio, not sure about xcode.

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

                On 20/04/2015 at 18:38, xxxxxxxx wrote:

                I am pretty certain that doing so causes the compiler to complain since they are needed.  Been there, tried that.  Maybe there are ways to circumvent it, but if you disable "Handle Exceptions" in a project, it typically errors on the build if there are exceptions in the code.

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

                  On 20/04/2015 at 19:46, xxxxxxxx wrote:

                  oh, I wasn't aware of this "I guess I'm learning more about exceptions everyday "

                  I don't want to jump over the thread with my questions now, but I'm curious about 2 things:
                  1- I'm using a dll which uses STL very heavily , is this safe?
                  2- any suggestion of STL like containers library that doesn't use exceptions? "I didn't try Boost yet but I don't know if it uses exceptions or not".

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

                    On 21/04/2015 at 00:47, xxxxxxxx wrote:

                    Originally posted by xxxxxxxx

                    How does one use, say, BaseArray with my_spline->GetPoints()?  Do you simply cast or does one need to copy the Vector* array into the BaseArray?  What exactly?  You guys continue to tout this stuff but where are the extensive usage examples?  Even these types are well hidden in the API docs.  And they are not used in the cinema4dsdk examples.  One reason that I don't use them is there is no exemplification of their usage.

                    If you look at my reply you'll see that I recommended using the BaseArray instead of the manual array Rui used in his first example.

                    You'll have to use the pointers/manual freeing as long as we keep the API compatible (and it took some efforts to keep the changes you had to apply to your plugin code minimal - compared to what changed internally in recent years).

                    Keeping the API compatible for a very wide range of plugins however won't be possible till infinity (if you look in the past there have been bigger changes like going from float to double in the scene format that broke API compatibility).

                    Therefore my advice is: Avoid manual arrays in your code (whenever possible), make yourself familiar with the BaseArray (and it's derivations), understand the usefulness of C++ 11 move semantics and spend some time with iterators.

                    Regarding examples in the SDK: Searching for "BaseArray" reveals 13 occurrencies in the R16 SDK
                    - activeobject.cpp
                    - arraytutorial.cpp
                    - edgecuttool.cpp
                    - gl_test_object.cpp
                    - memstat.cpp
                    - menutest.pp
                    - misctest.cpp
                    - movecopyconstructors.cpp
                    - paintundo.h
                    - pgp.cpp
                    - sculptbrushmultistamp.cpp
                    - sculptmodifier.cpp
                    - snaptool.cpp

                    Best regards,

                    Wilfried

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

                      On 21/04/2015 at 06:16, xxxxxxxx wrote:

                      Originally posted by xxxxxxxx

                      oh, I wasn't aware of this "I guess I'm learning more about exceptions everyday "

                      I don't want to jump over the thread with my questions now, but I'm curious about 2 things:
                      1- I'm using a dll which uses STL very heavily , is this safe?
                      2- any suggestion of STL like containers library that doesn't use exceptions? "I didn't try Boost yet but I don't know if it uses exceptions or not".

                      1.:  Not it is not really safe.  If you disable exceptions and STL try to throw one then you plugin will simple CRASH. 
                      AFAIK std::vector will throw exception only on memory errors. 
                      This is not that likely on 64bit system, but still possible.

                      2.: Well the first chose would be c4d_misc::BaseArray and Co.
                      Boost is based on STL and of course uses exceptions.

                      About GetPoints() and other such functions.
                      Most of them return pointer to memory that you do not Own  so you do not need BaseArrayfor this.  BaseArrayis need for arrays that you Own and responsible to free.

                      In other cases you can use RAII types like AutoGeFree from "ge_autoptr.h" header file.

                      Remo

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

                        On 23/04/2015 at 14:56, xxxxxxxx wrote:

                        Originally posted by xxxxxxxx

                        Well, my code is well behaved (I don't leave inbetween the new[] and delete[]) but I see your point.

                        How can you be sure about this ?  🙂

                        http://bromeon.ch/articles/raii.html

                        Remo

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

                          On 24/04/2015 at 01:46, xxxxxxxx wrote:

                          Because all my returns checks are performed before the creation of the arrays. In between the creation and deletion, there are no returns.
                          So, I'm pretty sure there are no arrays left hanging.
                          But, in the future, I will use BaseArray 🙂

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

                            On 24/04/2015 at 02:31, xxxxxxxx wrote:

                            Originally posted by xxxxxxxx

                            Originally posted by xxxxxxxx

                            oh, I wasn't aware of this "I guess I'm learning more about exceptions everyday "

                            I don't want to jump over the thread with my questions now, but I'm curious about 2 things:
                            1- I'm using a dll which uses STL very heavily , is this safe?
                            2- any suggestion of STL like containers library that doesn't use exceptions? "I didn't try Boost yet but I don't know if it uses exceptions or not".

                            1.:  Not it is not really safe.  If you disable exceptions and STL try to throw one then you plugin will simple CRASH. 
                            AFAIK std::vector will throw exception only on memory errors. 
                            This is not that likely on 64bit system, but still possible.

                            2.: Well the first chose would be c4d_misc::BaseArray and Co.
                            Boost is based on STL and of course uses exceptions.

                            About GetPoints() and other such functions.
                            Most of them return pointer to memory that you do not Own  so you do not need BaseArrayfor this.  BaseArrayis need for arrays that you Own and responsible to free.

                            In other cases you can use RAII types like AutoGeFree from "ge_autoptr.h" header file.

                            Remo

                            Also, you will have problems if you write to the std::vector in two different modules as they are
                            (especially in a C4D plugin) likely to use a different memory allocator. If you append to the vector
                            in your C4D plugin so that new memory must be (re-allocated) but the vector becomes destroyed in
                            DLL, it will most likely crash.

                            -Niklas

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