gNew



  • 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



  • 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">_letev"> whereever possible.



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



  • 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



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


Log in to reply