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

    gNew

    Scheduled Pinned Locked Moved SDK Help
    5 Posts 0 Posters 476 Views
    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 Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 15/05/2012 at 06:16, xxxxxxxx wrote:

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

      ---------
      I should know this by now and I feel stupid for asking this late in the game and I can't find it after doing some searches so I thought I'd ask.  Please don't laugh at the simplicity and naivety of this question.  LOL

      What is the advantage of using gNew over the c++ "new" keyword for allocating my own classes?  I assume it has to do with C4D's memory management but I thought I would ask anyway.  Sorry if this is a repeat question.   🙂

      ~Shawn

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 15/05/2012 at 06:22, xxxxxxxx wrote:

        Sorry!  I found my answer:

        From SDK:

        Memory Management_<_h4_>_

        In the past the CINEMA 4D SDK overloaded the operators new and delete. This is no longer the case. new and delete will allocate and free memory from the operating system, to allow easier linking of DLLs and DYLIBs.

        CINEMA 4D data structures where control is passed on to CINEMA 4D (so that you don't free it yourself anymore) must be allocated with gNew and gDelete)) (or bNew and bDelete() for arrays). In general, we recommend to make use of gNew/gDelete()\_w">[URL-REMOVED]\_letev">[URL-REMOVED] whereever possible.


        [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

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

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 16/05/2012 at 00:04, xxxxxxxx wrote:

          Remember that Cinema 4D is targetted at several different operating systems (Windows, MacOS, and Linux) so it is a good practice to put a layer between system/language support dependencies so that you don't have to deal with them.  gNew() et al provide a ubiquitous interface for the C++ operators that removes this possible complexity.

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

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 16/05/2012 at 04:45, xxxxxxxx wrote:

            Thanks Robert,

            So I should use gNew and gDelete for my own classes and not the C++ new operator?

            Also,  if I use gNew for my own class and then I push that instance of my class in to a GeAutoDynamicArray of that class, does the Dynamic Array take ownership of the memory so I don't need to call gDelete on that instance?  Meaning when I call myArray.FreeArray() does that free the memory from the instance I pushed in to the array?

            Thanks,

            Shawn

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

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 16/05/2012 at 09:19, xxxxxxxx wrote:

              You need to call .Free() (FreeArray() in R13) to deallocate the memory stored in the dynamic array.  If you want to manage the memory yourself, call Release().  See GeDynamicArray in the sdk documentation.

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